From aa83628383f45cc3620bd34d53e93856a6da3895 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Tue, 18 Jun 2024 12:51:24 +0000 Subject: [PATCH 1/5] fix parital update --- source/util/src/tcompression.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/source/util/src/tcompression.c b/source/util/src/tcompression.c index 4635ec340d..1e7e09794f 100644 --- a/source/util/src/tcompression.c +++ b/source/util/src/tcompression.c @@ -2918,6 +2918,7 @@ int32_t tcompressDebug(uint32_t cmprAlg, uint8_t *l1Alg, uint8_t *l2Alg, uint8_t } int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, uint8_t lvlDiabled, uint8_t lvlDefault, uint32_t *dst) { + int8_t update = 0; uint8_t ol1 = COMPRESS_L1_TYPE_U32(oldCmpr); uint8_t ol2 = COMPRESS_L2_TYPE_U32(oldCmpr); uint8_t olvl = COMPRESS_L2_TYPE_LEVEL_U32(oldCmpr); @@ -2927,8 +2928,11 @@ int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, u uint8_t nlvl = COMPRESS_L2_TYPE_LEVEL_U32(newCmpr); if (nl1 != 0 && ol1 != nl1) { SET_COMPRESS(nl1, ol2, olvl, *dst); - return 1; - } else if (nl2 != 0 && ol2 != nl2) { + update = 1; + ol1 = nl1; + } + + if (nl2 != 0 && ol2 != nl2) { if (nl2 == l2Disabled) { SET_COMPRESS(ol1, nl2, lvlDiabled, *dst); } else { @@ -2938,10 +2942,13 @@ int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, u SET_COMPRESS(ol1, nl2, olvl, *dst); } } - return 1; - } else if (nlvl != 0 && olvl != nlvl) { - SET_COMPRESS(ol1, ol2, nlvl, *dst); - return 1; + update = 1; + ol2 = nl2; } - return 0; + + if (nlvl != 0 && olvl != nlvl) { + SET_COMPRESS(ol1, ol2, nlvl, *dst); + update = 1; + } + return update; } From e4916d13a5c245820e3918bf623107b0b15395c1 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 19 Jun 2024 12:11:03 +0000 Subject: [PATCH 2/5] update case --- source/util/src/tcompression.c | 7 +++++++ tests/script/tsim/compress/compress2.sim | 25 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/source/util/src/tcompression.c b/source/util/src/tcompression.c index 1e7e09794f..0cc822da4c 100644 --- a/source/util/src/tcompression.c +++ b/source/util/src/tcompression.c @@ -2916,7 +2916,9 @@ int32_t tcompressDebug(uint32_t cmprAlg, uint8_t *l1Alg, uint8_t *l2Alg, uint8_t *level = lvl; return 0; } + int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, uint8_t lvlDiabled, uint8_t lvlDefault, + uint32_t *dst) { int8_t update = 0; uint8_t ol1 = COMPRESS_L1_TYPE_U32(oldCmpr); @@ -2926,6 +2928,10 @@ int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, u uint8_t nl1 = COMPRESS_L1_TYPE_U32(newCmpr); uint8_t nl2 = COMPRESS_L2_TYPE_U32(newCmpr); uint8_t nlvl = COMPRESS_L2_TYPE_LEVEL_U32(newCmpr); + + // nl1 == 0, not update encode + // nl2 == 0, not update compress + // nl3 == 0, not update level if (nl1 != 0 && ol1 != nl1) { SET_COMPRESS(nl1, ol2, olvl, *dst); update = 1; @@ -2950,5 +2956,6 @@ int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, u SET_COMPRESS(ol1, ol2, nlvl, *dst); update = 1; } + return update; } diff --git a/tests/script/tsim/compress/compress2.sim b/tests/script/tsim/compress/compress2.sim index a439d75a59..0af6f87de4 100644 --- a/tests/script/tsim/compress/compress2.sim +++ b/tests/script/tsim/compress/compress2.sim @@ -163,6 +163,31 @@ sql alter table $stb modify column f compress 'zlib' sql desc $stb sql alter table $stb modify column f compress 'zstd' + +sql alter table $stb modify column f compress 'zstd' level 'h' +sql_error alter table $stb modify column f compress 'zstd' level 'h' + +sql alter table $stb modify column f compress 'lz4' level 'h' +sql_error alter table $stb modify column f compress 'lz4' level 'h' + + +sql alter table $stb modify column f level 'low' +sql_error alter table $stb modify column f compress 'lz4' + +sql_error alter table $stb modify column f compress 'lz4' level 'low' + +sql alter table $stb modify column f compress 'zstd' level 'h' + +sql_error alter table $stb modify column f compress 'zstd' +sql_error alter table $stb modify column f level 'h' + + + +sql alter table $stb modify column f compress 'lz4' + + + + sql_error alter table $stb modify column d compress 'lz4' # same with init sql alter table $stb modify column d compress 'disabled' sql desc $stb From 01ee8b36a4424a98a0d3002ffc6969972df8e9ef Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 19 Jun 2024 12:35:38 +0000 Subject: [PATCH 3/5] update case --- source/dnode/mnode/impl/src/mndStb.c | 6 +++++- source/dnode/vnode/src/meta/metaTable.c | 7 ++++++- source/util/src/tcompression.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 0d3affe6e5..41ca6aadc2 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1766,7 +1766,7 @@ static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj * uint32_t dst = 0; updated = tUpdateCompress(pCmpr->alg, p->bytes, TSDB_COLVAL_COMPRESS_DISABLED, TSDB_COLVAL_LEVEL_DISABLED, TSDB_COLVAL_LEVEL_MEDIUM, &dst); - if (updated) pCmpr->alg = dst; + if (updated > 0) pCmpr->alg = dst; break; } } @@ -1774,7 +1774,11 @@ static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj * if (updated == 0) { terrno = TSDB_CODE_MND_COLUMN_COMPRESS_ALREADY_EXIST; return -1; + } else if (update == -1) { + terrno = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR; + return -1; } + pNew->colVer++; return 0; diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 2a122081b8..4c0091fcb7 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2240,7 +2240,7 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq * uint32_t dst = 0; updated = tUpdateCompress(p->alg, pReq->compress, TSDB_COLVAL_COMPRESS_DISABLED, TSDB_COLVAL_LEVEL_DISABLED, TSDB_COLVAL_LEVEL_MEDIUM, &dst); - if (updated) { + if (updated > 0) { p->alg = dst; } } @@ -2250,6 +2250,11 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq * tDecoderClear(&dc); terrno = TSDB_CODE_VND_COLUMN_COMPRESS_ALREADY_EXIST; goto _err; + } else if (update < 0) { + tdbFree(pVal); + tDecoderClear(&dc); + terrno = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR; + goto _err; } tbEntry.version = version; diff --git a/source/util/src/tcompression.c b/source/util/src/tcompression.c index 0cc822da4c..92d8ca3313 100644 --- a/source/util/src/tcompression.c +++ b/source/util/src/tcompression.c @@ -2953,8 +2953,14 @@ int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, u } if (nlvl != 0 && olvl != nlvl) { - SET_COMPRESS(ol1, ol2, nlvl, *dst); - update = 1; + if (update == 0) { + if (ol2 == L2_DISABLED) { + update = -1; + } + } else { + SET_COMPRESS(ol1, ol2, nlvl, *dst); + update = 1; + } } return update; From 639df3dfad49950d177850908fbd318e18bc52dd Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 20 Jun 2024 00:13:32 +0000 Subject: [PATCH 4/5] update case --- source/dnode/mnode/impl/src/mndStb.c | 2 +- source/dnode/vnode/src/meta/metaTable.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 41ca6aadc2..8abcd1e9c8 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1774,7 +1774,7 @@ static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj * if (updated == 0) { terrno = TSDB_CODE_MND_COLUMN_COMPRESS_ALREADY_EXIST; return -1; - } else if (update == -1) { + } else if (updated == -1) { terrno = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR; return -1; } diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 4c0091fcb7..58eef3caa6 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -2250,7 +2250,7 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq * tDecoderClear(&dc); terrno = TSDB_CODE_VND_COLUMN_COMPRESS_ALREADY_EXIST; goto _err; - } else if (update < 0) { + } else if (updated < 0) { tdbFree(pVal); tDecoderClear(&dc); terrno = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR; From d0d155171c763a91792a0e59c54cc352ed22fab4 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 20 Jun 2024 02:02:22 +0000 Subject: [PATCH 5/5] update case --- source/util/src/tcompression.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/util/src/tcompression.c b/source/util/src/tcompression.c index 92d8ca3313..73875d836a 100644 --- a/source/util/src/tcompression.c +++ b/source/util/src/tcompression.c @@ -2956,11 +2956,11 @@ int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, u if (update == 0) { if (ol2 == L2_DISABLED) { update = -1; + return update; } - } else { - SET_COMPRESS(ol1, ol2, nlvl, *dst); - update = 1; } + SET_COMPRESS(ol1, ol2, nlvl, *dst); + update = 1; } return update;