将bucketname作为object_key的一部分;修改delete接口加入minioaddr和bucket可选参数。

This commit is contained in:
zhangchengwei
2018-12-15 13:50:48 +08:00
committed by zhengchao
parent 1059af3c72
commit a70aa35a3a
8 changed files with 56 additions and 82 deletions

View File

@@ -283,11 +283,11 @@ void tango_cache_get_object_path(struct tango_cache_ctx *ctx, char *path/*OUT*/,
{
if(ctx->locate == OBJECT_IN_MINIO)
{
snprintf(path, pathsize, "http://%s/%s/%s", ctx->hostaddr, ctx->instance->param->bucketname, ctx->object_key);
snprintf(path, pathsize, "http://%s/%s", ctx->hostaddr, ctx->object_key);
}
else
{
snprintf(path, pathsize, "redis://%s/%s/%s", ctx->instance->redisaddr, ctx->instance->param->bucketname, ctx->object_key);
snprintf(path, pathsize, "redis://%s/%s", ctx->instance->redisaddr, ctx->object_key);
}
}
}
@@ -405,14 +405,14 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
if(instance->param->hash_object_key)
{
caculate_sha256(meta->url, strlen(meta->url), buffer, 72);
snprintf(ctx->object_key, 256, "%c%c/%c%c/%s", buffer[0], buffer[1], buffer[2], buffer[3], buffer+4);
snprintf(ctx->object_key, 256, "%s/%c%c/%c%c/%s", instance->param->bucketname, buffer[0], buffer[1], buffer[2], buffer[3], buffer+4);
//<2F><><EFBFBD><EFBFBD>ԭʼURL
snprintf(buffer, 2064, "x-amz-meta-url: %s", meta->url);
ctx->headers = curl_slist_append(ctx->headers, buffer);
}
else
{
snprintf(ctx->object_key, 256, "%s", meta->url);
snprintf(ctx->object_key, 256, "%s/%s", instance->param->bucketname, meta->url);
}
if(wired_load_balancer_lookup(instance->param->minio.wiredlb, ctx->object_key, strlen(ctx->object_key), ctx->hostaddr, 48))
{
@@ -591,11 +591,11 @@ struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *i
if(instance->param->hash_object_key)
{
caculate_sha256(meta->url, strlen(meta->url), sha256, 72);
snprintf(ctx->object_key, 256, "%c%c/%c%c/%s", sha256[0], sha256[1], sha256[2], sha256[3], sha256+4);
snprintf(ctx->object_key, 256, "%s/%c%c/%c%c/%s", instance->param->bucketname, sha256[0], sha256[1], sha256[2], sha256[3], sha256+4);
}
else
{
snprintf(ctx->object_key, 256, "%s", meta->url);
snprintf(ctx->object_key, 256, "%s/%s", instance->param->bucketname, meta->url);
}
if(wired_load_balancer_lookup(instance->param->minio.wiredlb, ctx->object_key, strlen(ctx->object_key), ctx->hostaddr, 48))
{
@@ -639,10 +639,11 @@ int tango_cache_head_object(struct tango_cache_instance *instance, struct future
return do_tango_cache_head_object(ctx, location);
}
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* f, const char *objkey)
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* f, const char *objkey, const char *minio_addr, const char *bucket)
{
struct tango_cache_ctx *ctx;
char sha256[72];
const char *pbucket;
if(sessions_exceeds_limit(instance, OBJECT_IN_MINIO))
{
@@ -656,16 +657,21 @@ struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *
ctx->promise = future_to_promise(f);
ctx->method = CACHE_REQUEST_DELETE;
pbucket = (bucket==NULL)?instance->param->bucketname:bucket;
if(instance->param->hash_object_key)
{
caculate_sha256(objkey, strlen(objkey), sha256, 72);
snprintf(ctx->object_key, 256, "%c%c/%c%c/%s", sha256[0], sha256[1], sha256[2], sha256[3], sha256+4);
snprintf(ctx->object_key, 256, "%s/%c%c/%c%c/%s", pbucket, sha256[0], sha256[1], sha256[2], sha256[3], sha256+4);
}
else
{
snprintf(ctx->object_key, 256, "%s", objkey);
snprintf(ctx->object_key, 256, "%s/%s", pbucket, objkey);
}
if(wired_load_balancer_lookup(instance->param->minio.wiredlb, ctx->object_key, strlen(ctx->object_key), ctx->hostaddr, 48))
if(minio_addr != NULL)
{
snprintf(ctx->hostaddr, 48, "%s", minio_addr);
}
else if(wired_load_balancer_lookup(instance->param->minio.wiredlb, ctx->object_key, strlen(ctx->object_key), ctx->hostaddr, 48))
{
instance->error_code = CACHE_ERR_WIREDLB;
instance->statistic.totaldrop_num += 1;
@@ -675,11 +681,11 @@ struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *
return ctx;
}
int tango_cache_delete_object(struct tango_cache_instance *instance, struct future* f, const char *objkey)
int tango_cache_delete_object(struct tango_cache_instance *instance, struct future* f, const char *objkey, const char *minio_addr, const char *bucket)
{
struct tango_cache_ctx *ctx;
ctx = tango_cache_delete_prepare(instance, f, objkey);
ctx = tango_cache_delete_prepare(instance, f, objkey, minio_addr, bucket);
if(ctx == NULL)
{
return -1;