@@ -123,7 +123,7 @@ void CJHBlockCompressedSearchNode::load(CKeyHdr *_keyHdr, const void *rawData, o
123123 zeroFilePosition = *(bool *) keys;
124124 keys += sizeof (bool );
125125
126- keyRecLen = zeroFilePosition ? (keyLen + sizeof (offset_t )) : keyLen ;
126+ keyRecLen = zeroFilePosition ? keyLen : (keyLen + sizeof (offset_t ));
127127
128128 CCycleTimer expansionTimer (true );
129129 keyBuf = expandBlock (keys, inMemorySize, compressionMethod);
@@ -144,12 +144,12 @@ bool CJHBlockCompressedSearchNode::fetchPayload(unsigned int index, char *dst, P
144144 if (keyHdr->hasSpecialFileposition ())
145145 {
146146 if (zeroFilePosition)
147- memcpy (dst+keyCompareLen, p+keyCompareLen, keyLen + sizeof (offset_t ) - keyCompareLen);
148- else
149147 {
150148 memcpy (dst+keyCompareLen, p+keyCompareLen, keyLen-keyCompareLen);
151- *(( offset_t *) dst+keyLen) = 0 ;
149+ *(offset_t *)( dst+keyLen) = 0 ;
152150 }
151+ else
152+ memcpy (dst+keyCompareLen, p+keyCompareLen, keyLen + sizeof (offset_t ) - keyCompareLen);
153153 }
154154 else
155155 {
@@ -182,7 +182,7 @@ size32_t CJHBlockCompressedSearchNode::getSizeAt(unsigned int index) const
182182offset_t CJHBlockCompressedSearchNode::getFPosAt (unsigned int index) const
183183{
184184 if (index >= hdr.numKeys ) return 0 ;
185- if (! zeroFilePosition) return 0 ;
185+ if (zeroFilePosition) return 0 ;
186186
187187 offset_t pos;
188188 const char * p = keyBuf + index*keyRecLen + keyLen;
@@ -270,13 +270,13 @@ bool CBlockCompressedWriteNode::add(offset_t pos, const void *indata, size32_t i
270270 keyPtr += sizeof (context.compressionMethod );
271271 hdr.keyBytes += sizeof (context.compressionMethod );
272272
273- bool hasFilepos = !context.zeroFilePos ;
274- *(bool *)keyPtr = hasFilepos;
273+ *(bool *)keyPtr = context.zeroFilePos ;
275274 keyPtr += sizeof (bool );
276275 hdr.keyBytes += sizeof (bool );
277276
278277 // Adjust the fixed key size to include the fileposition field which is written by writekey
279278 bool isVariable = keyHdr->isVariable ();
279+ bool hasFilepos = !context.zeroFilePos ;
280280 size32_t fixedKeySize = isVariable ? 0 : (hasFilepos ? keyLen + sizeof (offset_t ) : keyLen);
281281
282282 ICompressHandler * handler = queryCompressHandler (context.compressionMethod );
@@ -306,7 +306,7 @@ void CBlockCompressedWriteNode::finalize()
306306
307307// =========================================================================================================
308308
309- BlockCompressedIndexCompressor::BlockCompressedIndexCompressor (unsigned keyedSize, IHThorIndexWriteArg *helper, const char * options)
309+ BlockCompressedIndexCompressor::BlockCompressedIndexCompressor (unsigned keyedSize, IHThorIndexWriteArg *helper, const char * options, bool isTLK )
310310{
311311 CompressionMethod compressionMethod = COMPRESS_METHOD_ZSTDS;
312312 StringBuffer compressionOptions;
@@ -336,7 +336,7 @@ BlockCompressedIndexCompressor::BlockCompressedIndexCompressor(unsigned keyedSiz
336336 if (!context.compressionHandler )
337337 throw MakeStringException (0 , " Unknown compression method %d" , (int )compressionMethod);
338338
339- if (helper && (helper->getFlags () & TIWzerofilepos))
339+ if (!isTLK && helper && (helper->getFlags () & TIWzerofilepos))
340340 context.zeroFilePos = true ;
341341}
342342
@@ -358,7 +358,7 @@ void CJHBlockCompressedVarNode::load(CKeyHdr *_keyHdr, const void *rawData, offs
358358 KEYRECSIZE_T recsize = *(KEYRECSIZE_T *)finger;
359359 _WINREV (recsize);
360360 finger += recsize + sizeof (KEYRECSIZE_T);
361- if (zeroFilePosition)
361+ if (! zeroFilePosition)
362362 finger += sizeof (offset_t );
363363 }
364364}
@@ -380,12 +380,12 @@ bool CJHBlockCompressedVarNode::fetchPayload(unsigned int num, char *dst, Payloa
380380 if (keyHdr->hasSpecialFileposition ())
381381 {
382382 if (zeroFilePosition)
383- memcpy (dst+keyCompareLen, p+keyCompareLen, reclen + sizeof (offset_t ) - keyCompareLen);
384- else
385383 {
386384 memcpy (dst+keyCompareLen, p+keyCompareLen, reclen-keyCompareLen);
387- *(( offset_t *) dst+reclen ) = 0 ;
385+ *(offset_t *)( dst+keyLen ) = 0 ;
388386 }
387+ else
388+ memcpy (dst+keyCompareLen, p+keyCompareLen, reclen + sizeof (offset_t ) - keyCompareLen);
389389 }
390390 else
391391 memcpy (dst+keyCompareLen, p+keyCompareLen, reclen-keyCompareLen);
0 commit comments