diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 879f8c6928933dffb503edb8b6e68de0b3c19b28..8efd58739dceac01b3c44e7a7e2abd4b3cb1866c 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -785,6 +785,8 @@ typedef struct { int32_t walRollPeriod; int64_t walSegmentSize; int32_t sstTrigger; + int16_t hashPrefix; + int16_t hashSuffix; } SCreateDbReq; int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq); @@ -1193,6 +1195,8 @@ typedef struct { int32_t walRollPeriod; int64_t walSegmentSize; int16_t sstTrigger; + int16_t hashPrefix; + int16_t hashSuffix; } SCreateVnodeReq; int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq); diff --git a/include/util/tdef.h b/include/util/tdef.h index 48f37fca2810deeea7814907dbbfb6471c13118f..57fde32bed5d27bee4f429644a4b4623c2abe64e 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -362,6 +362,12 @@ typedef enum ELogicConditionType { #define TSDB_MIN_SST_TRIGGER 1 #define TSDB_MAX_SST_TRIGGER 128 #define TSDB_DEFAULT_SST_TRIGGER 8 +#define TSDB_MIN_HASH_PREFIX 0 +#define TSDB_MAX_HASH_PREFIX 128 +#define TSDB_DEFAULT_HASH_PREFIX 0 +#define TSDB_MIN_HASH_SUFFIX 0 +#define TSDB_MAX_HASH_SUFFIX 128 +#define TSDB_DEFAULT_HASH_SUFFIX 0 #define TSDB_DB_MIN_WAL_RETENTION_PERIOD -1 #define TSDB_REP_DEF_DB_WAL_RET_PERIOD 0 diff --git a/include/util/tutil.h b/include/util/tutil.h index 6a1a40f14ccb865533f117524ffdfef3c84e20ad..a0c7b3d7ad9826ec8ed6879c85e92315de70591b 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -20,6 +20,7 @@ #include "tcrc32c.h" #include "tdef.h" #include "tmd5.h" +#include "thash.h" #ifdef __cplusplus extern "C" { @@ -68,6 +69,8 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar memcpy(target, buf, TSDB_PASSWORD_LEN); } +#define taosGetTbHashVal(tbname, tblen, method, prefix, suffix) MurmurHash3_32((tbname), (tblen)) + #ifdef __cplusplus } #endif diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 9947d0e3b28d2039e3d9fd3d6f8573aa368d7550..9b6737a210ffa8993e0adb7013ea0bbea136d13d 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2025,6 +2025,8 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { if (tEncodeI32(&encoder, pReq->walRollPeriod) < 0) return -1; if (tEncodeI64(&encoder, pReq->walSegmentSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->sstTrigger) < 0) return -1; + if (tEncodeI16(&encoder, pReq->hashPrefix) < 0) return -1; + if (tEncodeI16(&encoder, pReq->hashSuffix) < 0) return -1; if (tEncodeI8(&encoder, pReq->ignoreExist) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfRetensions) < 0) return -1; for (int32_t i = 0; i < pReq->numOfRetensions; ++i) { @@ -2072,6 +2074,8 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) if (tDecodeI32(&decoder, &pReq->walRollPeriod) < 0) return -1; if (tDecodeI64(&decoder, &pReq->walSegmentSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->sstTrigger) < 0) return -1; + if (tDecodeI16(&decoder, &pReq->hashPrefix) < 0) return -1; + if (tDecodeI16(&decoder, &pReq->hashSuffix) < 0) return -1; if (tDecodeI8(&decoder, &pReq->ignoreExist) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1; pReq->pRetensions = taosArrayInit(pReq->numOfRetensions, sizeof(SRetention)); @@ -3767,6 +3771,8 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR if (tEncodeI32(&encoder, pReq->walRollPeriod) < 0) return -1; if (tEncodeI64(&encoder, pReq->walSegmentSize) < 0) return -1; if (tEncodeI16(&encoder, pReq->sstTrigger) < 0) return -1; + if (tEncodeI16(&encoder, pReq->hashPrefix) < 0) return -1; + if (tEncodeI16(&encoder, pReq->hashSuffix) < 0) return -1; tEndEncode(&encoder); @@ -3840,6 +3846,8 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq * if (tDecodeI32(&decoder, &pReq->walRollPeriod) < 0) return -1; if (tDecodeI64(&decoder, &pReq->walSegmentSize) < 0) return -1; if (tDecodeI16(&decoder, &pReq->sstTrigger) < 0) return -1; + if (tDecodeI16(&decoder, &pReq->hashPrefix) < 0) return -1; + if (tDecodeI16(&decoder, &pReq->hashSuffix) < 0) return -1; tEndDecode(&decoder); tDecoderClear(&decoder); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index c684683ee9438dfbe635da33ff17c0c0f66009e3..830bf9523a60e703f797ab60160717d39c0e615f 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -171,6 +171,8 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pCfg->hashBegin = pCreate->hashBegin; pCfg->hashEnd = pCreate->hashEnd; pCfg->hashMethod = pCreate->hashMethod; + pCfg->hashPrefix = pCreate->hashPrefix; + pCfg->hashSuffix = pCreate->hashSuffix; pCfg->standby = pCfg->standby; pCfg->syncCfg.myIndex = pCreate->selfIndex; @@ -220,9 +222,11 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return -1; } - dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d cacheLast:%d cacheLastSize:%d sstTrigger:%d", + dInfo("vgId:%d, start to create vnode, tsma:%d standby:%d cacheLast:%d cacheLastSize:%d sstTrigger:%d", createReq.vgId, createReq.isTsma, createReq.standby, createReq.cacheLast, createReq.cacheLastSize, createReq.sstTrigger); + dInfo("vgId:%d, hashMethod:%d begin:%u end:%u prefix:%d surfix:%d", createReq.vgId, createReq.hashMethod, + createReq.hashBegin, createReq.hashEnd, createReq.hashPrefix, createReq.hashSuffix); vmGenerateVnodeCfg(&createReq, &vnodeCfg); if (vmTsmaAdjustDays(&vnodeCfg, &createReq) < 0) { diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 179e7f44486b7499d4ec3617ece0ca1c721c05f7..2268a18455658080ddbfdd46d3593f068255f505 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -305,13 +305,15 @@ typedef struct { int8_t hashMethod; // default is 1 int8_t cacheLast; int8_t schemaless; + int16_t hashPrefix; + int16_t hashSuffix; + int16_t sstTrigger; int32_t numOfRetensions; SArray* pRetensions; int32_t walRetentionPeriod; - int64_t walRetentionSize; int32_t walRollPeriod; + int64_t walRetentionSize; int64_t walSegmentSize; - int16_t sstTrigger; } SDbCfg; typedef struct { diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index d1313d5a1712d308a546baa1305b4896b678ddf2..d808dfbbf3d30892c0d58fe7ae49a497ee4f01d0 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -30,7 +30,7 @@ #include "systable.h" #define DB_VER_NUMBER 1 -#define DB_RESERVE_SIZE 62 +#define DB_RESERVE_SIZE 58 static SSdbRaw *mndDbActionEncode(SDbObj *pDb); static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw); @@ -125,6 +125,8 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { SDB_SET_INT32(pRaw, dataPos, pDb->cfg.walRollPeriod, _OVER) SDB_SET_INT64(pRaw, dataPos, pDb->cfg.walSegmentSize, _OVER) SDB_SET_INT16(pRaw, dataPos, pDb->cfg.sstTrigger, _OVER) + SDB_SET_INT16(pRaw, dataPos, pDb->cfg.hashPrefix, _OVER) + SDB_SET_INT16(pRaw, dataPos, pDb->cfg.hashSuffix, _OVER) SDB_SET_RESERVE(pRaw, dataPos, DB_RESERVE_SIZE, _OVER) SDB_SET_DATALEN(pRaw, dataPos, _OVER) @@ -209,6 +211,8 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.walRollPeriod, _OVER) SDB_GET_INT64(pRaw, dataPos, &pDb->cfg.walSegmentSize, _OVER) SDB_GET_INT16(pRaw, dataPos, &pDb->cfg.sstTrigger, _OVER) + SDB_GET_INT16(pRaw, dataPos, &pDb->cfg.hashPrefix, _OVER) + SDB_GET_INT16(pRaw, dataPos, &pDb->cfg.hashSuffix, _OVER) SDB_GET_RESERVE(pRaw, dataPos, DB_RESERVE_SIZE, _OVER) taosInitRWLatch(&pDb->lock); @@ -334,6 +338,8 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->walRollPeriod < TSDB_DB_MIN_WAL_ROLL_PERIOD) return -1; if (pCfg->walSegmentSize < TSDB_DB_MIN_WAL_SEGMENT_SIZE) return -1; if (pCfg->sstTrigger < TSDB_MIN_SST_TRIGGER || pCfg->sstTrigger > TSDB_MAX_SST_TRIGGER) return -1; + if (pCfg->hashPrefix < TSDB_MIN_HASH_PREFIX || pCfg->hashPrefix > TSDB_MAX_HASH_PREFIX) return -1; + if (pCfg->hashSuffix < TSDB_MIN_HASH_SUFFIX || pCfg->hashSuffix > TSDB_MAX_HASH_SUFFIX) return -1; terrno = 0; return terrno; @@ -368,6 +374,8 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->walRollPeriod < 0) pCfg->walRollPeriod = TSDB_REPS_DEF_DB_WAL_ROLL_PERIOD; if (pCfg->walSegmentSize < 0) pCfg->walSegmentSize = TSDB_DEFAULT_DB_WAL_SEGMENT_SIZE; if (pCfg->sstTrigger <= 0) pCfg->sstTrigger = TSDB_DEFAULT_SST_TRIGGER; + if (pCfg->hashPrefix < 0) pCfg->hashPrefix = TSDB_DEFAULT_HASH_PREFIX; + if (pCfg->hashSuffix < 0) pCfg->hashSuffix = TSDB_DEFAULT_HASH_SUFFIX; } static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) { @@ -485,6 +493,8 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, .walRollPeriod = pCreate->walRollPeriod, .walSegmentSize = pCreate->walSegmentSize, .sstTrigger = pCreate->sstTrigger, + .hashPrefix = pCreate->hashPrefix, + .hashSuffix = pCreate->hashSuffix, }; dbObj.cfg.numOfRetensions = pCreate->numOfRetensions; diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index f54e831b0b342befa98702ece9c3f91e902fcf8c..d5f9f8a5cf66637aa915ee0bba315fc42f7510df 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -235,6 +235,8 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg createReq.walRollPeriod = pDb->cfg.walRollPeriod; createReq.walSegmentSize = pDb->cfg.walSegmentSize; createReq.sstTrigger = pDb->cfg.sstTrigger; + createReq.hashPrefix = pDb->cfg.hashPrefix; + createReq.hashSuffix = pDb->cfg.hashSuffix; for (int32_t v = 0; v < pVgroup->replica; ++v) { SReplica *pReplica = &createReq.replicas[v]; diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index a1c2265c2ef6281d0a55b4f6436ec4c46ff54d72..0fea96764e453cf4456e3d9572a6833df517b6a3 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -288,6 +288,8 @@ struct SVnodeCfg { uint32_t hashBegin; uint32_t hashEnd; int16_t sstTrigger; + int16_t hashPrefix; + int16_t hashSuffix; }; typedef struct { diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index 24dda293304b4845f4b4754393e05a15db167b42..f379d9f71afdf62089fb3f864ff2d0ac376d6997 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -14,6 +14,7 @@ */ #include "vnd.h" +#include "tutil.h" const SVnodeCfg vnodeCfgDefault = {.vgId = -1, .dbname = "", @@ -110,6 +111,8 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) { if (tjsonAddIntegerToObject(pJson, "hashBegin", pCfg->hashBegin) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "hashEnd", pCfg->hashEnd) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "hashMethod", pCfg->hashMethod) < 0) return -1; + if (tjsonAddIntegerToObject(pJson, "hashPrefix", pCfg->hashPrefix) < 0) return -1; + if (tjsonAddIntegerToObject(pJson, "hashSuffix", pCfg->hashSuffix) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex) < 0) return -1; @@ -214,6 +217,10 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (code < 0) return -1; tjsonGetNumberValue(pJson, "hashMethod", pCfg->hashMethod, code); if (code < 0) return -1; + tjsonGetNumberValue(pJson, "hashPrefix", pCfg->hashPrefix, code); + if (code < 0) return -1; + tjsonGetNumberValue(pJson, "hashSuffix", pCfg->hashSuffix, code); + if (code < 0) return -1; tjsonGetNumberValue(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum, code); if (code < 0) return -1; @@ -250,7 +257,8 @@ int vnodeValidateTableHash(SVnode *pVnode, char *tableFName) { switch (pVnode->config.hashMethod) { default: - hashValue = MurmurHash3_32(tableFName, strlen(tableFName)); + hashValue = taosGetTbHashVal(tableFName, strlen(tableFName), pVnode->config.hashMethod, pVnode->config.hashPrefix, + pVnode->config.hashSuffix); break; }