已合并
memcache接口错误码整改 #457
lichunyang创建于 26 天前
memcache接口错误码整改 #457
已合并
lichunyang创建于 26 天前
7 个文件变更+58-38
@@ -695,6 +695,7 @@ virtual int GetLocalServiceId(uint32_t &localServiceId) = 0;
695| -3009 | 网络序列号重复 |695| -3009 | 网络序列号重复 |
696| -3010 | 网络序列号未找到 |696| -3010 | 网络序列号未找到 |
697| -3011 | 已通知 |697| -3011 | 已通知 |
698+| -3012 | 内部错误 |
698| -3013 | 超出容量限制 |699| -3013 | 超出容量限制 |
699| -3014 | 连接未找到 |700| -3014 | 连接未找到 |
700| -3015 | 网络请求句柄未找到 |701| -3015 | 网络请求句柄未找到 |
@@ -706,7 +707,7 @@ virtual int GetLocalServiceId(uint32_t &localServiceId) = 0;
706| -3102 | 键不匹配 |707| -3102 | 键不匹配 |
707| -3103 | 返回值不匹配 |708| -3103 | 返回值不匹配 |
708| -3104 | 租约未到期 |709| -3104 | 租约未到期 |
709-| -3105 | 元数据备份失败 |710+| -3105 | 元数据备份失败 |
710 711 
711## 注意事项712## 注意事项
712 713 
@@ -747,6 +747,7 @@ TLS配置结构体,包含以下字段:
747| -3009 | 网络序列号重复 |747| -3009 | 网络序列号重复 |
748| -3010 | 网络序列号未找到 |748| -3010 | 网络序列号未找到 |
749| -3011 | 已通知 |749| -3011 | 已通知 |
750+| -3012 | 内部错误 |
750| -3013 | 超出容量限制 |751| -3013 | 超出容量限制 |
751| -3014 | 连接未找到 |752| -3014 | 连接未找到 |
752| -3015 | 网络请求句柄未找到 |753| -3015 | 网络请求句柄未找到 |
@@ -758,7 +759,7 @@ TLS配置结构体,包含以下字段:
758| -3102 | 键不匹配 |759| -3102 | 键不匹配 |
759| -3103 | 返回值不匹配 |760| -3103 | 返回值不匹配 |
760| -3104 | 租约未到期 |761| -3104 | 租约未到期 |
761-| -3105 | 元数据备份失败 |762+| -3105 | 元数据备份失败 |
762 763 
763## 注意事项764## 注意事项
764 765 
@@ -1160,33 +1160,34 @@ store.close()
1160 1160 
1161## 错误码1161## 错误码
1162 1162 
1163-| 错误码 | 说明 |1163+| 错误码 | 说明 |
1164-| ------- | --------------------- |1164+|-------|-----------|
1165-| 0 | 操作成功 |1165+| 0 | 操作成功 |
1166-| -1 | 一般错误 |1166+| -1 | 一般错误 |
1167-| -3000 | 参数无效 |1167+| -3000 | 参数无效 |
1168-| -3001 | 内存分配失败 |1168+| -3001 | 内存分配失败 |
1169-| -3002 | 对象创建失败 |1169+| -3002 | 对象创建失败 |
1170-| -3003 | 服务未启动 |1170+| -3003 | 服务未启动 |
1171-| -3004 | 操作超时 |1171+| -3004 | 操作超时 |
1172-| -3005 | 重复调用 |1172+| -3005 | 重复调用 |
1173-| -3006 | 对象已存在 |1173+| -3006 | 对象已存在 |
1174-| -3007 | 对象不存在 |1174+| -3007 | 对象不存在 |
1175-| -3008 | 未初始化 |1175+| -3008 | 未初始化 |
1176-| -3009 | 网络序列号重复 |1176+| -3009 | 网络序列号重复 |
1177-| -3010 | 网络序列号未找到 |1177+| -3010 | 网络序列号未找到 |
1178-| -3011 | 已通知 |1178+| -3011 | 已通知 |
1179-| -3013 | 超出容量限制 |1179+| -3012 | 内部错误 |
1180-| -3014 | 连接未找到 |1180+| -3013 | 超出容量限制 |
1181+| -3014 | 连接未找到 |
1181| -3015 | 网络请求句柄未找到 |1182| -3015 | 网络请求句柄未找到 |
1182-| -3016 | 内存不足 |1183+| -3016 | 内存不足 |
1183| -3017 | 未连接到元数据服务 |1184| -3017 | 未连接到元数据服务 |
1184-| -3018 | 未连接到本地服务 |1185+| -3018 | 未连接到本地服务 |
1185-| -3019 | 客户端未初始化 |1186+| -3019 | 客户端未初始化 |
1186-| -3101 | 状态不匹配 |1187+| -3101 | 状态不匹配 |
1187-| -3102 | 键不匹配 |1188+| -3102 | 键不匹配 |
1188-| -3103 | 返回值不匹配 |1189+| -3103 | 返回值不匹配 |
1189-| -3104 | 租约未到期 |1190+| -3104 | 租约未到期 |
1190| -3105 | 元数据备份失败 |1191| -3105 | 元数据备份失败 |
1191 1192 
1192## 注意事项1193## 注意事项
@@ -467,7 +467,7 @@ Result MmcClientDefault::BatchGet(const std::vector<std::string> &keys, const st
467 return MMC_INVALID_PARAM;467 return MMC_INVALID_PARAM;
468 }468 }
469 // get meta469 // get meta
470- batchResult.assign(keys.size(), MMC_ERROR);470+ batchResult.assign(keys.size(), MMC_INVALID_PARAM);
471 const uint64_t operateId = GenerateOperateId(rankId_);471 const uint64_t operateId = GenerateOperateId(rankId_);
472 BatchGetRequest request{keys, rankId_, operateId};472 BatchGetRequest request{keys, rankId_, operateId};
473 BatchAllocResponse response;473 BatchAllocResponse response;
@@ -494,12 +494,14 @@ Result MmcClientDefault::BatchGet(const std::vector<std::string> &keys, const st
494 if (numBlobs <= 0 || blobs.empty() || blobs.size() != numBlobs) {494 if (numBlobs <= 0 || blobs.empty() || blobs.size() != numBlobs) {
495 MMC_LOG_ERROR("client " << name_ << " batch get failed for key " << keys[i]495 MMC_LOG_ERROR("client " << name_ << " batch get failed for key " << keys[i]
496 << ", blob:" << std::to_string(numBlobs) << ", size:" << blobs.size());496 << ", blob:" << std::to_string(numBlobs) << ", size:" << blobs.size());
497+ batchResult[i] = MMC_OBJECT_NOT_EXISTS;
497 continue;498 continue;
498 }499 }
499 if (bufArr.TotalSize() != blobs[0].size_) {500 if (bufArr.TotalSize() != blobs[0].size_) {
500 MMC_LOG_ERROR("client " << name_ << " batch get failed for key " << keys[i]501 MMC_LOG_ERROR("client " << name_ << " batch get failed for key " << keys[i]
501 << ", blob:" << std::to_string(numBlobs) << ", size:" << blobs[0].size_502 << ", blob:" << std::to_string(numBlobs) << ", size:" << blobs[0].size_
502 << " key size:" << bufArr.TotalSize());503 << " key size:" << bufArr.TotalSize());
504+ batchResult[i] = MMC_INTERNAL_ERROR;
503 continue;505 continue;
504 }506 }
505 507 
@@ -38,6 +38,7 @@ enum MmcErrorCode : int32_t {
38 MMC_NET_SEQ_DUP = -3009,38 MMC_NET_SEQ_DUP = -3009,
39 MMC_NET_SEQ_NO_FOUND = -3010,39 MMC_NET_SEQ_NO_FOUND = -3010,
40 MMC_ALREADY_NOTIFIED = -3011,40 MMC_ALREADY_NOTIFIED = -3011,
41+ MMC_INTERNAL_ERROR = -3012,
41 MMC_EXCEED_CAPACITY = -3013,42 MMC_EXCEED_CAPACITY = -3013,
42 MMC_LINK_NOT_FOUND = -3014,43 MMC_LINK_NOT_FOUND = -3014,
43 MMC_NET_REQ_HANDLE_NO_FOUND = -3015,44 MMC_NET_REQ_HANDLE_NO_FOUND = -3015,
@@ -80,6 +80,7 @@ MMC_API int32_t mmcc_put(const char *key, mmc_buffer *buf, mmc_put_options optio
80 MMC_VALIDATE_RETURN(strlen(key) <= MAX_KEY_LEN, "invalid param, key's len more than 256", MMC_INVALID_PARAM);80 MMC_VALIDATE_RETURN(strlen(key) <= MAX_KEY_LEN, "invalid param, key's len more than 256", MMC_INVALID_PARAM);
81 MMC_VALIDATE_RETURN(buf != nullptr, "invalid param, buf is null", MMC_INVALID_PARAM);81 MMC_VALIDATE_RETURN(buf != nullptr, "invalid param, buf is null", MMC_INVALID_PARAM);
82 MMC_VALIDATE_RETURN((void *)buf->addr != nullptr, "invalid param, buf addr is null", MMC_INVALID_PARAM);82 MMC_VALIDATE_RETURN((void *)buf->addr != nullptr, "invalid param, buf addr is null", MMC_INVALID_PARAM);
83+ MMC_VALIDATE_RETURN(buf->len != 0, "invalid param, buf len equals 0", MMC_INVALID_PARAM);
83 MMC_VALIDATE_RETURN(MmcClientDefault::GetInstance() != nullptr, "client is not initialize", MMC_CLIENT_NOT_INIT);84 MMC_VALIDATE_RETURN(MmcClientDefault::GetInstance() != nullptr, "client is not initialize", MMC_CLIENT_NOT_INIT);
84 85 
85 auto ret = MmcClientDefault::GetInstance()->Put(key, buf, options, flags);86 auto ret = MmcClientDefault::GetInstance()->Put(key, buf, options, flags);
@@ -97,6 +98,7 @@ MMC_API int32_t mmcc_get(const char *key, mmc_buffer *buf, uint32_t flags)
97 MMC_VALIDATE_RETURN(strlen(key) <= MAX_KEY_LEN, "invalid param, key's len more than 256", MMC_INVALID_PARAM);98 MMC_VALIDATE_RETURN(strlen(key) <= MAX_KEY_LEN, "invalid param, key's len more than 256", MMC_INVALID_PARAM);
98 MMC_VALIDATE_RETURN(buf != nullptr, "invalid param, buf is null", MMC_INVALID_PARAM);99 MMC_VALIDATE_RETURN(buf != nullptr, "invalid param, buf is null", MMC_INVALID_PARAM);
99 MMC_VALIDATE_RETURN(buf->addr != 0, "invalid param, buf addr is null", MMC_INVALID_PARAM);100 MMC_VALIDATE_RETURN(buf->addr != 0, "invalid param, buf addr is null", MMC_INVALID_PARAM);
101+ MMC_VALIDATE_RETURN(buf->len != 0, "invalid param, buf len equals 0", MMC_INVALID_PARAM);
100 MMC_VALIDATE_RETURN(MmcClientDefault::GetInstance() != nullptr, "client is not initialize", MMC_CLIENT_NOT_INIT);102 MMC_VALIDATE_RETURN(MmcClientDefault::GetInstance() != nullptr, "client is not initialize", MMC_CLIENT_NOT_INIT);
101 103 
102 MMC_RETURN_ERROR(MmcClientDefault::GetInstance()->Get(key, buf, flags), MmcClientDefault::GetInstance()->Name()104 MMC_RETURN_ERROR(MmcClientDefault::GetInstance()->Get(key, buf, flags), MmcClientDefault::GetInstance()->Name()
@@ -465,7 +467,7 @@ MMC_API int32_t mmcc_batch_get(const char **keys, uint32_t keys_count, mmc_buffe
465 467 
466 std::vector<std::string> keys_vector;468 std::vector<std::string> keys_vector;
467 std::vector<mmc_buffer> bufs_vector;469 std::vector<mmc_buffer> bufs_vector;
468- std::vector<int> batchResult(keys_count, MMC_ERROR);470+ std::vector<int> batchResult(keys_count, MMC_INVALID_PARAM);
469 keys_vector.reserve(keys_count);471 keys_vector.reserve(keys_count);
470 bufs_vector.reserve(keys_count);472 bufs_vector.reserve(keys_count);
471 473 
@@ -501,7 +503,7 @@ MMC_API int32_t mmcc_batch_put(const char **keys, uint32_t keys_count, const mmc
501 503 
502 std::vector<std::string> keys_vector;504 std::vector<std::string> keys_vector;
503 std::vector<mmc_buffer> bufs_vector;505 std::vector<mmc_buffer> bufs_vector;
504- std::vector<int> batchResult(keys_count, MMC_ERROR);506+ std::vector<int> batchResult(keys_count, MMC_INVALID_PARAM);
505 keys_vector.reserve(keys_count);507 keys_vector.reserve(keys_count);
506 bufs_vector.reserve(keys_count);508 bufs_vector.reserve(keys_count);
507 509 
@@ -515,8 +517,9 @@ MMC_API int32_t mmcc_batch_put(const char **keys, uint32_t keys_count, const mmc
515 MMC_LOG_ERROR("Remove invalid key: " << keys[i]);517 MMC_LOG_ERROR("Remove invalid key: " << keys[i]);
516 return MMC_INVALID_PARAM; // 这个错误属于入参不合法,直接给调用者返回错误518 return MMC_INVALID_PARAM; // 这个错误属于入参不合法,直接给调用者返回错误
517 }519 }
518- if (bufs == nullptr || bufs[i].addr == 0 || bufs[i].type >= BUF_TYPE_BASE) {520+ if (bufs == nullptr || bufs[i].addr == 0 || bufs[i].type >= BUF_TYPE_BASE || bufs[i].len == 0) {
519- MMC_LOG_ERROR("Remove invalid buf with key: " << keys[i] << ", type: " << bufs[i].type);521+ MMC_LOG_ERROR("Remove invalid buf with key: " << keys[i] << ", type: " << bufs[i].type
522+ << ", len: " << bufs[i].len);
520 return MMC_INVALID_PARAM;523 return MMC_INVALID_PARAM;
521 }524 }
522 keys_vector.emplace_back(keys[i]);525 keys_vector.emplace_back(keys[i]);
@@ -445,7 +445,7 @@ std::vector<int> MmcacheStore::BatchPutFrom(const std::vector<std::string> &keys
445 const size_t count = keys.size();445 const size_t count = keys.size();
446 MMC_VALIDATE_RETURN(count > 0, "key vector is empty", {});446 MMC_VALIDATE_RETURN(count > 0, "key vector is empty", {});
447 447 
448- std::vector<int> results(count, -1);448+ std::vector<int> results(count, MMC_INVALID_PARAM);
449 if (buffers.size() != count || sizes.size() != count) {449 if (buffers.size() != count || sizes.size() != count) {
450 MMC_LOG_ERROR("Input vector sizes mismatch: keys=" << keys.size() << ", buffers=" << buffers.size()450 MMC_LOG_ERROR("Input vector sizes mismatch: keys=" << keys.size() << ", buffers=" << buffers.size()
451 << ", sizes=" << sizes.size());451 << ", sizes=" << sizes.size());
@@ -492,7 +492,7 @@ std::vector<int> MmcacheStore::BatchGetInto(const std::vector<std::string> &keys
492 size_t count = keys.size();492 size_t count = keys.size();
493 MMC_VALIDATE_RETURN(count > 0, "key vector is empty", {});493 MMC_VALIDATE_RETURN(count > 0, "key vector is empty", {});
494 494 
495- std::vector<int> results(count, -1);495+ std::vector<int> results(count, MMC_INVALID_PARAM);
496 if (buffers.size() != count || sizes.size() != count) {496 if (buffers.size() != count || sizes.size() != count) {
497 MMC_LOG_ERROR("Input vector sizes mismatch: keys=" << keys.size() << ", buffers=" << buffers.size()497 MMC_LOG_ERROR("Input vector sizes mismatch: keys=" << keys.size() << ", buffers=" << buffers.size()
498 << ", sizes=" << sizes.size());498 << ", sizes=" << sizes.size());
@@ -514,6 +514,10 @@ std::vector<int> MmcacheStore::BatchGetInto(const std::vector<std::string> &keys
514 std::vector<const char *> keyArray(count);514 std::vector<const char *> keyArray(count);
515 std::vector<mmc_buffer> bufferArray(count);515 std::vector<mmc_buffer> bufferArray(count);
516 for (size_t i = 0; i < count; ++i) {516 for (size_t i = 0; i < count; ++i) {
517+ if (static_cast<uint64_t>(sizes[i]) == 0) {
518+ MMC_LOG_ERROR("Invalid vector sizes on idx [" << i << "] equals 0");
519+ return results;
520+ }
517 keyArray[i] = keys[i].c_str();521 keyArray[i] = keys[i].c_str();
518 bufferArray[i] = {.addr = reinterpret_cast<uint64_t>(buffers[i]),522 bufferArray[i] = {.addr = reinterpret_cast<uint64_t>(buffers[i]),
519 .type = type,523 .type = type,
@@ -541,8 +545,7 @@ int MmcacheStore::PutFromLayers(const std::string &key, const std::vector<void *
541 if (direct != SMEMB_COPY_L2G && direct != SMEMB_COPY_H2G && direct != SMEMB_COPY_AUTO) {545 if (direct != SMEMB_COPY_L2G && direct != SMEMB_COPY_H2G && direct != SMEMB_COPY_AUTO) {
542 MMC_LOG_ERROR(546 MMC_LOG_ERROR(
543 "Invalid direct(" << direct547 "Invalid direct(" << direct
544- << "), only"548+ << "), only 0 (SMEMB_COPY_L2G), 3 (SMEMB_COPY_H2G) and 9 (SMEMB_COPY_AUTO) is supported");
545- "0 (SMEMB_COPY_L2G), 3 (SMEMB_COPY_H2G) and 9 (SMEMB_COPY_AUTO) is supported");
546 return MMC_INVALID_PARAM;549 return MMC_INVALID_PARAM;
547 }550 }
548 551 
@@ -579,6 +582,10 @@ int MmcacheStore::PutFromLayers(const std::string &key, const std::vector<void *
579 Result res;582 Result res;
580 MmcBufferArray bufArr;583 MmcBufferArray bufArr;
581 for (size_t i = 0; i < layerNum; i += 1) {584 for (size_t i = 0; i < layerNum; i += 1) {
585+ if (static_cast<uint64_t>(sizes[i]) == 0) {
586+ MMC_LOG_ERROR("Invalid param, layers buf len on idx [" << i << "] equals 0");
587+ return MMC_INVALID_PARAM;
588+ }
582 bufArr.AddBuffer({.addr = reinterpret_cast<uint64_t>(buffers[i]),589 bufArr.AddBuffer({.addr = reinterpret_cast<uint64_t>(buffers[i]),
583 .type = type,590 .type = type,
584 .offset = 0,591 .offset = 0,
@@ -700,6 +707,10 @@ int MmcacheStore::GetIntoLayers(const std::string &key, const std::vector<void *
700 707 
701 std::vector<mmc_buffer> mmc_buffers;708 std::vector<mmc_buffer> mmc_buffers;
702 for (size_t i = 0; i < layerNum; i += 1) {709 for (size_t i = 0; i < layerNum; i += 1) {
710+ if (static_cast<uint64_t>(sizes[i]) == 0) {
711+ MMC_LOG_ERROR("Invalid param, layers buf len on idx [" << i << "] equals 0");
712+ return MMC_INVALID_PARAM;
713+ }
703 mmc_buffers.push_back({.addr = reinterpret_cast<uint64_t>(buffers[i]),714 mmc_buffers.push_back({.addr = reinterpret_cast<uint64_t>(buffers[i]),
704 .type = type,715 .type = type,
705 .offset = 0,716 .offset = 0,
@@ -840,7 +851,7 @@ int MmcacheStore::PutBatch(const std::vector<std::string> &keys, std::vector<mmc
840 const size_t count = keys.size();851 const size_t count = keys.size();
841 MMC_VALIDATE_RETURN(count > 0, "key vector is empty", 0);852 MMC_VALIDATE_RETURN(count > 0, "key vector is empty", 0);
842 853 
843- std::vector<int> results(count, -1);854+ std::vector<int> results(count, MMC_INVALID_PARAM);
844 if (buffers.size() != count) {855 if (buffers.size() != count) {
845 MMC_LOG_ERROR("Input vector sizes mismatch: keys=" << keys.size() << ", buffers=" << buffers.size());856 MMC_LOG_ERROR("Input vector sizes mismatch: keys=" << keys.size() << ", buffers=" << buffers.size());
846 return MMC_INVALID_PARAM;857 return MMC_INVALID_PARAM;
@@ -909,7 +920,7 @@ std::vector<mmc_buffer> MmcacheStore::GetBatch(const std::vector<std::string> &k
909 size_t count = keys.size();920 size_t count = keys.size();
910 MMC_VALIDATE_RETURN(count > 0, "key vector is empty", {});921 MMC_VALIDATE_RETURN(count > 0, "key vector is empty", {});
911 922 
912- std::vector<int> results(count, -1);923+ std::vector<int> results(count, MMC_INVALID_PARAM);
913 std::vector<mmc_buffer> buffers(count, {0, 0, 0, 0});924 std::vector<mmc_buffer> buffers(count, {0, 0, 0, 0});
914 std::vector<const char *> keyArray(count);925 std::vector<const char *> keyArray(count);
915 926