• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4513

17 Jul 2025 02:02AM UTC coverage: 31.359% (-31.1%) from 62.446%
#4513

push

travis-ci

web-flow
Merge pull request #31914 from taosdata/fix/3.0/compare-ans-failed

fix:Convert line endings from LF to CRLF for ans file

68541 of 301034 branches covered (22.77%)

Branch coverage included in aggregate %.

117356 of 291771 relevant lines covered (40.22%)

602262.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/include/libs/executor/storageapi.h
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#ifndef TDENGINE_STORAGEAPI_H
17
#define TDENGINE_STORAGEAPI_H
18

19
#include "function.h"
20
#include "index.h"
21
#include "taosdef.h"
22
#include "tcommon.h"
23
#include "tmsg.h"
24
#include "tscalablebf.h"
25
#include "tsimplehash.h"
26

27
#ifdef __cplusplus
28
extern "C" {
29
#endif
30

31
#define TIMEWINDOW_RANGE_CONTAINED 1
32
#define TIMEWINDOW_RANGE_EXTERNAL  2
33

34
#define CACHESCAN_RETRIEVE_TYPE_ALL    0x1
35
#define CACHESCAN_RETRIEVE_TYPE_SINGLE 0x2
36
#define CACHESCAN_RETRIEVE_LAST_ROW    0x4
37
#define CACHESCAN_RETRIEVE_LAST        0x8
38

39
#define META_READER_LOCK   0x0
40
#define META_READER_NOLOCK 0x1
41

42
#define STREAM_STATE_BUFF_HASH        1
43
#define STREAM_STATE_BUFF_SORT        2
44
#define STREAM_STATE_BUFF_HASH_SORT   3
45
#define STREAM_STATE_BUFF_HASH_SEARCH 4
46

47
typedef struct SMeta SMeta;
48
typedef TSKEY (*GetTsFun)(void*);
49

50
typedef struct SMetaEntry {
51
  int64_t  version;
52
  int8_t   type;
53
  int8_t   flags;  // TODO: need refactor?
54
  tb_uid_t uid;
55
  char*    name;
56
  union {
57
    struct {
58
      SSchemaWrapper schemaRow;
59
      SSchemaWrapper schemaTag;
60
      SRSmaParam     rsmaParam;
61
      int64_t        keep;
62
    } stbEntry;
63
    struct {
64
      int64_t  btime;
65
      int32_t  ttlDays;
66
      int32_t  commentLen;  // not include '\0'
67
      char*    comment;
68
      tb_uid_t suid;
69
      uint8_t* pTags;
70
    } ctbEntry;
71
    struct {
72
      int64_t        btime;
73
      int32_t        ttlDays;
74
      int32_t        commentLen;
75
      char*          comment;
76
      int32_t        ncid;  // next column id
77
      SSchemaWrapper schemaRow;
78
    } ntbEntry;
79
    struct {
80
      STSma* tsma;
81
    } smaEntry;
82
  };
83

84
  uint8_t* pBuf;
85

86
  SColCmprWrapper colCmpr;  // col compress alg
87
  SExtSchema*     pExtSchemas;
88
  SColRefWrapper  colRef;   // col reference for virtual table
89
} SMetaEntry;
90

91
typedef struct SMetaReader {
92
  int32_t            flags;
93
  void*              pMeta;
94
  SDecoder           coder;
95
  SMetaEntry         me;
96
  void*              pBuf;
97
  int32_t            szBuf;
98
  struct SStoreMeta* pAPI;
99
} SMetaReader;
100

101
typedef struct SMTbCursor {
102
  void*       pMeta;
103
  void*       pDbc;
104
  void*       pKey;
105
  void*       pVal;
106
  int32_t     kLen;
107
  int32_t     vLen;
108
  SMetaReader mr;
109
  int8_t      paused;
110
} SMTbCursor;
111

112
typedef struct SMCtbCursor {
113
  struct SMeta* pMeta;
114
  void*         pCur;
115
  tb_uid_t      suid;
116
  void*         pKey;
117
  void*         pVal;
118
  int           kLen;
119
  int           vLen;
120
  int8_t        paused;
121
  int           lock;
122
} SMCtbCursor;
123

124
typedef struct SRowBuffPos {
125
  void* pRowBuff;
126
  void* pKey;
127
  bool  beFlushed;
128
  bool  beUsed;
129
  bool  needFree;
130
  bool  beUpdated;
131
  bool  invalid;
132
} SRowBuffPos;
133

134
// tq
135
typedef struct SMetaTableInfo {
136
  int64_t         suid;
137
  int64_t         uid;
138
  SSchemaWrapper* schema;
139
  char            tbName[TSDB_TABLE_NAME_LEN];
140
} SMetaTableInfo;
141

142
static FORCE_INLINE void destroyMetaTableInfo(SMetaTableInfo* mtInfo){
143
  if (mtInfo == NULL) return;
×
144
  tDeleteSchemaWrapper(mtInfo->schema);
×
145
}
146

147
typedef struct SSnapContext {
148
  struct SMeta* pMeta;
149
  int64_t       snapVersion;
150
  void*         pCur;
151
  int64_t       suid;
152
  int8_t        subType;
153
  SHashObj*     idVersion;
154
  SHashObj*     suidInfo;
155
  SArray*       idList;
156
  int32_t       index;
157
  int8_t        withMeta;
158
  int8_t        queryMeta;  // true-get meta, false-get data
159
  bool          hasPrimaryKey;
160
} SSnapContext;
161

162
typedef struct {
163
  int64_t uid;
164
  int64_t ctbNum;
165
  int32_t colNum;
166
  int8_t  flags;
167
  int64_t keep;
168
} SMetaStbStats;
169

170
// clang-format off
171
/*-------------------------------------------------new api format---------------------------------------------------*/
172
typedef enum {
173
  TSD_READER_NOTIFY_DURATION_START,
174
  TSD_READER_NOTIFY_NEXT_DURATION_BLOCK,
175
} ETsdReaderNotifyType;
176

177
typedef union {
178
  struct {
179
    int32_t filesetId;
180
  } duration;
181
} STsdReaderNotifyInfo;
182

183
typedef void (*TsdReaderNotifyCbFn)(ETsdReaderNotifyType type, STsdReaderNotifyInfo* info, void* param);
184

185
struct SFileSetReader;
186

187
typedef struct TsdReader {
188
  int32_t      (*tsdReaderOpen)(void* pVnode, SQueryTableDataCond* pCond, void* pTableList, int32_t numOfTables,
189
                           SSDataBlock* pResBlock, void** ppReader, const char* idstr, SHashObj** pIgnoreTables);
190
  void         (*tsdReaderClose)(void* pReader);
191
  int32_t      (*tsdSetReaderTaskId)(void* pReader, const char* pId);
192
  int32_t      (*tsdSetQueryTableList)(void* p, const void* pTableList, int32_t num);
193
  int32_t      (*tsdNextDataBlock)(void* pReader, bool* hasNext);
194

195
  int32_t      (*tsdReaderRetrieveBlockSMAInfo)();
196
  int32_t      (*tsdReaderRetrieveDataBlock)(void* p, SSDataBlock** pBlock, SArray* pIdList);
197

198
  void         (*tsdReaderReleaseDataBlock)(void* pReader);
199

200
  int32_t      (*tsdReaderResetStatus)(void* p, SQueryTableDataCond* pCond);
201
  int32_t      (*tsdReaderGetDataBlockDistInfo)();
202
  int64_t      (*tsdReaderGetNumOfInMemRows)();
203
  void         (*tsdReaderNotifyClosing)();
204

205
  void         (*tsdSetFilesetDelimited)(void* pReader);
206
  void         (*tsdSetSetNotifyCb)(void* pReader, TsdReaderNotifyCbFn notifyFn, void* param);
207

208
  // for fileset query
209
  int32_t (*fileSetReaderOpen)(void *pVnode, struct SFileSetReader **ppReader);
210
  int32_t (*fileSetReadNext)(struct SFileSetReader *);
211
  int32_t (*fileSetGetEntryField)(struct SFileSetReader *, const char *, void *);
212
  void (*fileSetReaderClose)(struct SFileSetReader **);
213

214
  int32_t (*getProgress)(const void* pReader, void** pBuf, uint64_t* pLen);
215
  int32_t (*setProgress)(void *pReader, const void *pBuf, uint64_t len);
216
} TsdReader;
217

218
typedef struct SStoreCacheReader {
219
  int32_t  (*openReader)(void *pVnode, int32_t type, void *pTableIdList, int32_t numOfTables, int32_t numOfCols,
220
                         SArray *pCidList, int32_t *pSlotIds, uint64_t suid, void **pReader, const char *idstr,
221
                         SArray *pFuncTypeList, SColumnInfo* pPkCol, int32_t numOfPks);
222
  void     (*closeReader)(void *pReader);
223
  int32_t  (*retrieveRows)(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds, const int32_t *dstSlotIds,
224
                           SArray *pTableUidList, bool* pGotAllRows);
225
  int32_t  (*reuseReader)(void *pReader, void *pTableIdList, int32_t numOfTables);
226
} SStoreCacheReader;
227

228
// clang-format on
229

230
/*------------------------------------------------------------------------------------------------------------------*/
231
// todo rename
232
typedef struct SStoreTqReader {
233
  struct STqReader* (*tqReaderOpen)();
234
  void (*tqReaderClose)();
235

236
  int32_t (*tqReaderSeek)();
237
  bool (*tqReaderNextBlockInWal)();
238
  bool (*tqNextBlockImpl)();  // todo remove it
239
  SSDataBlock* (*tqGetResultBlock)();
240
  int64_t (*tqGetResultBlockTime)();
241

242
  int32_t (*tqReaderSetColIdList)();
243
  int32_t (*tqReaderSetQueryTableList)();
244

245
  void (*tqReaderAddTables)();
246
  void (*tqReaderRemoveTables)();
247

248
  void (*tqSetTablePrimaryKey)();
249
  bool (*tqGetTablePrimaryKey)();
250
  bool (*tqReaderIsQueriedTable)();
251
  bool (*tqReaderCurrentBlockConsumed)();
252

253
  struct SWalReader* (*tqReaderGetWalReader)();  // todo remove it
254
                                                 //  int32_t (*tqReaderRetrieveTaosXBlock)();       // todo remove it
255

256
  int32_t (*tqReaderSetSubmitMsg)();  // todo remove it
257
  //  bool (*tqReaderNextBlockFilterOut)();
258

259
  int32_t (*tqReaderSetVtableInfo)();
260
} SStoreTqReader;
261

262
typedef struct SStoreSnapshotFn {
263
  bool (*taosXGetTablePrimaryKey)(SSnapContext* ctx);
264
  void (*taosXSetTablePrimaryKey)(SSnapContext* ctx, int64_t uid);
265
  int32_t (*setForSnapShot)(SSnapContext* ctx, int64_t uid);
266
  void (*destroySnapshot)(SSnapContext* ctx);
267
  int32_t (*getMetaTableInfoFromSnapshot)(SSnapContext* ctx, SMetaTableInfo* info);
268
  int32_t (*getTableInfoFromSnapshot)(SSnapContext* ctx, void** pBuf, int32_t* contLen, int16_t* type, int64_t* uid);
269
} SStoreSnapshotFn;
270

271
typedef struct SStoreMeta {
272
  SMTbCursor* (*openTableMetaCursor)(void* pVnode);                                 // metaOpenTbCursor
273
  void (*closeTableMetaCursor)(SMTbCursor* pTbCur);                                 // metaCloseTbCursor
274
  void (*pauseTableMetaCursor)(SMTbCursor* pTbCur);                                 // metaPauseTbCursor
275
  int32_t (*resumeTableMetaCursor)(SMTbCursor* pTbCur, int8_t first, int8_t move);  // metaResumeTbCursor
276
  int32_t (*cursorNext)(SMTbCursor* pTbCur, ETableType jumpTableType);              // metaTbCursorNext
277
  int32_t (*cursorPrev)(SMTbCursor* pTbCur, ETableType jumpTableType);              // metaTbCursorPrev
278

279
  int32_t (*getTableTags)(void* pVnode, uint64_t suid, SArray* uidList);
280
  int32_t (*getTableTagsByUid)(void* pVnode, int64_t suid, SArray* uidList);
281
  const void* (*extractTagVal)(const void* tag, int16_t type, STagVal* tagVal);  // todo remove it
282

283
  int32_t (*getTableUidByName)(void* pVnode, char* tbName, uint64_t* uid);
284
  int32_t (*getTableTypeSuidByName)(void* pVnode, char* tbName, ETableType* tbType, uint64_t* suid);
285
  int32_t (*getTableNameByUid)(void* pVnode, uint64_t uid, char* tbName);
286
  bool (*isTableExisted)(void* pVnode, tb_uid_t uid);
287

288
  int32_t (*metaGetCachedTbGroup)(void* pVnode, tb_uid_t suid, const uint8_t* pKey, int32_t keyLen, SArray** pList);
289
  int32_t (*metaPutTbGroupToCache)(void* pVnode, uint64_t suid, const void* pKey, int32_t keyLen, void* pPayload,
290
                                   int32_t payloadLen);
291

292
  int32_t (*getCachedTableList)(void* pVnode, tb_uid_t suid, const uint8_t* pKey, int32_t keyLen, SArray* pList1,
293
                                bool* acquireRes);
294
  int32_t (*putCachedTableList)(void* pVnode, uint64_t suid, const void* pKey, int32_t keyLen, void* pPayload,
295
                                int32_t payloadLen, double selectivityRatio);
296

297
  int32_t (*metaGetCachedRefDbs)(void* pVnode, tb_uid_t suid, SArray* pList);
298
  int32_t (*metaPutRefDbsToCache)(void* pVnode, tb_uid_t suid, SArray* pList);
299

300
  void* (*storeGetIndexInfo)(void* pVnode);
301
  void* (*getInvertIndex)(void* pVnode);
302
  // support filter and non-filter cases. [vnodeGetCtbIdList & vnodeGetCtbIdListByFilter]
303
  int32_t (*getChildTableList)(void* pVnode, int64_t suid, SArray* list);
304
  int32_t (*storeGetTableList)(void* pVnode, int8_t type, SArray* pList);
305
  int32_t (*getTableSchema)(void* pVnode, int64_t uid, STSchema** pSchema, int64_t* suid, SSchemaWrapper** pTagSchema);
306
  int32_t (*getNumOfChildTables)(void* pVnode, int64_t uid, int64_t* numOfTables, int32_t* numOfCols, int8_t* flags);
307
  void (*getBasicInfo)(void* pVnode, const char** dbname, int32_t* vgId, int64_t* numOfTables,
308
                       int64_t* numOfNormalTables);
309
  int32_t (*getDBSize)(void* pVnode, SDbSizeStatisInfo* pInfo);
310

311
  SMCtbCursor* (*openCtbCursor)(void* pVnode, tb_uid_t uid, int lock);
312
  int32_t (*resumeCtbCursor)(SMCtbCursor* pCtbCur, int8_t first);
313
  void (*pauseCtbCursor)(SMCtbCursor* pCtbCur);
314
  void (*closeCtbCursor)(SMCtbCursor* pCtbCur);
315
  tb_uid_t (*ctbCursorNext)(SMCtbCursor* pCur);
316
} SStoreMeta;
317

318
typedef struct SStoreMetaReader {
319
  void (*initReader)(SMetaReader* pReader, void* pVnode, int32_t flags, SStoreMeta* pAPI);
320
  void (*clearReader)(SMetaReader* pReader);
321
  void (*readerReleaseLock)(SMetaReader* pReader);
322
  int32_t (*getTableEntryByUid)(SMetaReader* pReader, tb_uid_t uid);
323
  int     (*getTableEntryByVersionUid)(SMetaReader *pReader, int64_t version, tb_uid_t uid);
324
  int32_t (*getTableEntryByName)(SMetaReader* pReader, const char* name);
325
  int32_t (*getEntryGetUidCache)(SMetaReader* pReader, tb_uid_t uid);
326
} SStoreMetaReader;
327

328
typedef struct SUpdateInfo {
329
  SArray*      pTsBuckets;
330
  uint64_t     numBuckets;
331
  SArray*      pTsSBFs;
332
  uint64_t     numSBFs;
333
  int64_t      interval;
334
  int64_t      watermark;
335
  TSKEY        minTS;
336
  SScalableBf* pCloseWinSBF;
337
  SHashObj*    pMap;
338
  int64_t      maxDataVersion;
339
  int8_t       pkColType;
340
  int32_t      pkColLen;
341
  char*        pKeyBuff;
342
  char*        pValueBuff;
343

344
  int (*comparePkRowFn)(void* pValue1, void* pTs, void* pPkVal, __compar_fn_t cmpPkFn);
345
  __compar_fn_t comparePkCol;
346
} SUpdateInfo;
347

348
typedef struct SRecDataInfo {
349
  STimeWindow calWin;
350
  uint64_t    tableUid;
351
  int64_t     dataVersion;
352
  EStreamType mode;
353
  char        pPkColData[];
354
} SRecDataInfo;
355

356
typedef struct SScanRange {
357
  STimeWindow win;
358
  STimeWindow calWin;
359
  SSHashObj*  pGroupIds;
360
  SSHashObj*  pUIds;
361
} SScanRange;
362

363
typedef struct SResultWindowInfo {
364
  SRowBuffPos* pStatePos;
365
  SSessionKey  sessionWin;
366
  bool         isOutput;
367
} SResultWindowInfo;
368

369
typedef struct {
370
  void*   iter;      //  rocksdb_iterator_t*    iter;
371
  void*   snapshot;  //  rocksdb_snapshot_t*    snapshot;
372
  void*   readOpt;   //  rocksdb_readoptions_t* readOpt;
373
  void*   db;        //  rocksdb_t*             db;
374
  void*   pCur;
375
  int64_t number;
376
  void*   pStreamFileState;
377
  int32_t buffIndex;
378
  int32_t hashIter;
379
  void*   pHashData;
380
  int64_t minGpId;
381
} SStreamStateCur;
382

383
typedef struct STableTsDataState {
384
  SSHashObj*       pTableTsDataMap;
385
  __compar_fn_t    comparePkColFn;
386
  void*            pPkValBuff;
387
  int32_t          pkValLen;
388
  SStreamState*    pState;
389
  int32_t          curRecId;
390
  void*            pStreamTaskState;
391
  SArray*          pScanRanges;
392
  SRecDataInfo*    pRecValueBuff;
393
  int32_t          recValueLen;
394
  SStreamStateCur* pRecCur;
395
  int32_t          cfgIndex;
396
  void*            pBatch;
397
  int32_t          batchBufflen;
398
  void*            pBatchBuff;
399
} STableTsDataState;
400

401
typedef struct SStateStore {
402
  int32_t (*streamStatePutParName)(SStreamState* pState, int64_t groupId, const char* tbname);
403
  int32_t (*streamStateGetParName)(SStreamState* pState, int64_t groupId, void** pVal, bool onlyCache,
404
                                   int32_t* pWinCode);
405
  int32_t (*streamStateDeleteParName)(SStreamState* pState, int64_t groupId);
406
  void (*streamStateSetParNameInvalid)(SStreamState* pState);
407

408
  int32_t (*streamStateAddIfNotExist)(SStreamState* pState, const SWinKey* pKey, void** pVal, int32_t* pVLen,
409
                                      int32_t* pWinCode);
410
  void (*streamStateReleaseBuf)(SStreamState* pState, void* pVal, bool used);
411
  void (*streamStateClearBuff)(SStreamState* pState, void* pVal);
412
  void (*streamStateFreeVal)(void* val);
413
  int32_t (*streamStateGetPrev)(SStreamState* pState, const SWinKey* pKey, SWinKey* pResKey, void** pVal,
414
                                int32_t* pVLen, int32_t* pWinCode);
415
  int32_t (*streamStateGetAllPrev)(SStreamState* pState, const SWinKey* pKey, SArray* pResArray, int32_t maxNum);
416

417
  int32_t (*streamStatePut)(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
418
  int32_t (*streamStateGet)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen, int32_t* pWinCode);
419
  bool (*streamStateCheck)(SStreamState* pState, const SWinKey* key, bool hasLimit, bool* pIsLast);
420
  bool (*streamStateCheckSessionState)(SStreamState* pState, SSessionKey* pKey, TSKEY gap, bool* pIsLast);
421
  int32_t (*streamStateGetByPos)(SStreamState* pState, void* pos, void** pVal);
422
  void (*streamStateDel)(SStreamState* pState, const SWinKey* key);
423
  void (*streamStateDelByGroupId)(SStreamState* pState, uint64_t groupId);
424
  void (*streamStateClear)(SStreamState* pState);
425
  void (*streamStateSetNumber)(SStreamState* pState, int32_t number, int32_t tsIdex);
426
  void (*streamStateSaveInfo)(SStreamState* pState, void* pKey, int32_t keyLen, void* pVal, int32_t vLen);
427
  int32_t (*streamStateGetInfo)(SStreamState* pState, void* pKey, int32_t keyLen, void** pVal, int32_t* pLen);
428
  int32_t (*streamStateGetNumber)(SStreamState* pState);
429
  int32_t (*streamStateDeleteInfo)(SStreamState* pState, void* pKey, int32_t keyLen);
430

431
  int32_t (*streamStateFillPut)(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
432
  int32_t (*streamStateFillGet)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen,
433
                                int32_t* pWinCode);
434
  int32_t (*streamStateFillAddIfNotExist)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen,
435
                                          int32_t* pWinCode);
436
  void (*streamStateFillDel)(SStreamState* pState, const SWinKey* key);
437
  int32_t (*streamStateFillGetNext)(SStreamState* pState, const SWinKey* pKey, SWinKey* pResKey, void** pVal,
438
                                    int32_t* pVLen, int32_t* pWinCode);
439
  int32_t (*streamStateFillGetPrev)(SStreamState* pState, const SWinKey* pKey, SWinKey* pResKey, void** pVal,
440
                                    int32_t* pVLen, int32_t* pWinCode);
441

442
  void (*streamStateCurNext)(SStreamState* pState, SStreamStateCur* pCur);
443
  void (*streamStateCurPrev)(SStreamState* pState, SStreamStateCur* pCur);
444

445
  SStreamStateCur* (*streamStateGetAndCheckCur)(SStreamState* pState, SWinKey* key);
446
  SStreamStateCur* (*streamStateSeekKeyNext)(SStreamState* pState, const SWinKey* key);
447
  SStreamStateCur* (*streamStateFillSeekKeyNext)(SStreamState* pState, const SWinKey* key);
448
  SStreamStateCur* (*streamStateFillSeekKeyPrev)(SStreamState* pState, const SWinKey* key);
449
  void (*streamStateFreeCur)(SStreamStateCur* pCur);
450

451
  int32_t (*streamStateFillGetGroupKVByCur)(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
452
  int32_t (*streamStateGetKVByCur)(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
453

454
  void (*streamStateClearExpiredState)(SStreamState* pState, int32_t numOfKeep, TSKEY minTs);
455
  void (*streamStateClearExpiredSessionState)(SStreamState* pState, int32_t numOfKeep, TSKEY minTs, SSHashObj* pFlushGroup);
456
  int32_t (*streamStateSetRecFlag)(SStreamState* pState, const void* pKey, int32_t keyLen, int32_t mode);
457
  int32_t (*streamStateGetRecFlag)(SStreamState* pState, const void* pKey, int32_t keyLen, int32_t* pMode);
458

459
  int32_t (*streamStateSessionAddIfNotExist)(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal,
460
                                             int32_t* pVLen, int32_t* pWinCode);
461
  int32_t (*streamStateSessionPut)(SStreamState* pState, const SSessionKey* key, void* value, int32_t vLen);
462
  int32_t (*streamStateSessionGet)(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen,
463
                                   int32_t* pWinCode);
464
  void (*streamStateSessionDel)(SStreamState* pState, const SSessionKey* key);
465
  void (*streamStateSessionReset)(SStreamState* pState, void* pVal);
466
  void (*streamStateSessionClear)(SStreamState* pState);
467
  int32_t (*streamStateSessionGetKVByCur)(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
468
  int32_t (*streamStateStateAddIfNotExist)(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
469
                                           state_key_cmpr_fn fn, void** pVal, int32_t* pVLen, int32_t* pWinCode);
470
  int32_t (*streamStateSessionGetKeyByRange)(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
471
  int32_t (*streamStateCountGetKeyByRange)(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
472
  int32_t (*streamStateSessionAllocWinBuffByNextPosition)(SStreamState* pState, SStreamStateCur* pCur,
473
                                                          const SSessionKey* pKey, void** pVal, int32_t* pVLen);
474
  int32_t (*streamStateSessionSaveToDisk)(STableTsDataState* pTblState, SSessionKey* pKey, SRecDataInfo* pVal, int32_t vLen);
475
  int32_t (*streamStateFlushReaminInfoToDisk)(STableTsDataState* pTblState);
476
  int32_t (*streamStateSessionDeleteAll)(SStreamState* pState);
477

478
  int32_t (*streamStateCountWinAddIfNotExist)(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount,
479
                                              void** ppVal, int32_t* pVLen, int32_t* pWinCode);
480
  int32_t (*streamStateCountWinAdd)(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal,
481
                                    int32_t* pVLen);
482

483
  int32_t (*updateInfoInit)(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType,
484
                            int32_t pkLen, SUpdateInfo** ppInfo);
485
  int32_t (*updateInfoFillBlockData)(SUpdateInfo* pInfo, SSDataBlock* pBlock, int32_t primaryTsCol,
486
                                     int32_t primaryKeyCol, TSKEY* pMaxResTs);
487
  bool (*updateInfoIsUpdated)(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
488
  bool (*updateInfoIsTableInserted)(SUpdateInfo* pInfo, int64_t tbUid);
489
  bool (*isIncrementalTimeStamp)(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
490

491
  void (*updateInfoDestroy)(SUpdateInfo* pInfo);
492
  void (*windowSBfDelete)(SUpdateInfo* pInfo, uint64_t count);
493
  int32_t (*windowSBfAdd)(SUpdateInfo* pInfo, uint64_t count);
494

495
  int32_t (*updateInfoInitP)(SInterval* pInterval, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen,
496
                             SUpdateInfo** ppInfo);
497
  void (*updateInfoAddCloseWindowSBF)(SUpdateInfo* pInfo);
498
  void (*updateInfoDestoryColseWinSBF)(SUpdateInfo* pInfo);
499
  int32_t (*updateInfoSerialize)(SEncoder* pEncoder, const SUpdateInfo* pInfo);
500
  int32_t (*updateInfoDeserialize)(SDecoder* pDeCoder, SUpdateInfo* pInfo);
501

502
  SStreamStateCur* (*streamStateSessionSeekKeyPrev)(SStreamState* pState, const SSessionKey* key);
503
  SStreamStateCur* (*streamStateSessionSeekKeyNext)(SStreamState* pState, const SSessionKey* key);
504
  SStreamStateCur* (*streamStateCountSeekKeyPrev)(SStreamState* pState, const SSessionKey* pKey, COUNT_TYPE count);
505
  SStreamStateCur* (*streamStateSessionSeekKeyCurrentPrev)(SStreamState* pState, const SSessionKey* key);
506
  SStreamStateCur* (*streamStateSessionSeekKeyCurrentNext)(SStreamState* pState, const SSessionKey* key);
507

508
  int32_t (*streamFileStateInit)(int64_t memSize, uint32_t keySize, uint32_t rowSize, uint32_t selectRowSize,
509
                                 GetTsFun fp, void* pFile, TSKEY delMark, const char* id, int64_t ckId, int8_t type,
510
                                 struct SStreamFileState** ppFileState);
511

512
  int32_t (*streamStateGroupPut)(SStreamState* pState, int64_t groupId, void* value, int32_t vLen);
513
  SStreamStateCur* (*streamStateGroupGetCur)(SStreamState* pState);
514
  void (*streamStateGroupCurNext)(SStreamStateCur* pCur);
515
  int32_t (*streamStateGroupGetKVByCur)(SStreamStateCur* pCur, int64_t* pKey, void** pVal, int32_t* pVLen);
516

517
  void (*streamFileStateDestroy)(struct SStreamFileState* pFileState);
518
  void (*streamFileStateClear)(struct SStreamFileState* pFileState);
519
  bool (*needClearDiskBuff)(struct SStreamFileState* pFileState);
520

521
  SStreamState* (*streamStateOpen)(const char* path, void* pTask, int64_t streamId, int32_t taskId);
522
  SStreamState* (*streamStateRecalatedOpen)(const char* path, void* pTask, int64_t streamId, int32_t taskId);
523
  void (*streamStateClose)(SStreamState* pState, bool remove);
524
  int32_t (*streamStateBegin)(SStreamState* pState);
525
  void (*streamStateCommit)(SStreamState* pState);
526
  void (*streamStateDestroy)(SStreamState* pState, bool remove);
527
  void (*streamStateReloadInfo)(SStreamState* pState, TSKEY ts);
528
  void (*streamStateCopyBackend)(SStreamState* src, SStreamState* dst);
529

530
  int32_t (*streamStateGetAndSetTsData)(STableTsDataState* pState, uint64_t tableUid, TSKEY* pCurTs, void** ppCurPkVal,
531
                                        TSKEY lastTs, void* pLastPkVal, int32_t lastPkLen, int32_t* pWinCode);
532
  int32_t (*streamStateTsDataCommit)(STableTsDataState* pState);
533
  int32_t (*streamStateInitTsDataState)(STableTsDataState** ppTsDataState, int8_t pkType, int32_t pkLen, void* pState, void* pOtherState);
534
  void (*streamStateDestroyTsDataState)(STableTsDataState* pTsDataState);
535
  int32_t (*streamStateRecoverTsData)(STableTsDataState* pTsDataState);
536
  int32_t (*streamStateReloadTsDataState)(STableTsDataState* pTsDataState);
537
  int32_t (*streamStateMergeAndSaveScanRange)(STableTsDataState* pTsDataState, STimeWindow* pWin, uint64_t gpId,
538
                                              SRecDataInfo* pRecData, int32_t len);
539
  int32_t (*streamStateMergeAllScanRange)(STableTsDataState* pTsDataState);
540
  int32_t (*streamStatePopScanRange)(STableTsDataState* pTsDataState, SScanRange* pRange);
541

542
  SStreamStateCur* (*streamStateGetLastStateCur)(SStreamState* pState);
543
  void (*streamStateLastStateCurNext)(SStreamStateCur* pCur);
544
  int32_t (*streamStateNLastStateGetKVByCur)(SStreamStateCur* pCur, int32_t num, SArray* pRes);
545
  SStreamStateCur* (*streamStateGetLastSessionStateCur)(SStreamState* pState);
546
  void (*streamStateLastSessionStateCurNext)(SStreamStateCur* pCur);
547
  int32_t (*streamStateNLastSessionStateGetKVByCur)(SStreamStateCur* pCur, int32_t num, SArray* pRes);
548
} SStateStore;
549

550
typedef struct SStorageAPI {
551
  SStoreMeta          metaFn;  // todo: refactor
552
  TsdReader           tsdReader;
553
  SStoreMetaReader    metaReaderFn;
554
  SStoreCacheReader   cacheFn;
555
  SStoreSnapshotFn    snapshotFn;
556
  SStoreTqReader      tqReaderFn;
557
  SStateStore         stateStore;
558
  SMetaDataFilterAPI  metaFilter;
559
  SFunctionStateStore functionStore;
560
} SStorageAPI;
561

562
#ifdef __cplusplus
563
}
564
#endif
565

566
#endif  // TDENGINE_STORAGEAPI_H
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc