1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef SQLITE_SINGLE_VER_RELATIONAL_STORAGE_EXECUTOR_H 16 #define SQLITE_SINGLE_VER_RELATIONAL_STORAGE_EXECUTOR_H 17 #ifdef RELATIONAL_STORE 18 19 #include <atomic> 20 #include "cloud/asset_operation_utils.h" 21 #include "cloud/cloud_db_constant.h" 22 #include "cloud/cloud_store_types.h" 23 #include "cloud/cloud_upload_recorder.h" 24 #include "data_transformer.h" 25 #include "db_types.h" 26 #include "icloud_sync_storage_interface.h" 27 #include "macro_utils.h" 28 #include "query_object.h" 29 #include "relational_row_data.h" 30 #include "relational_store_delegate.h" 31 #include "relational_sync_data_inserter.h" 32 #include "sqlite_single_ver_relational_continue_token.h" 33 #include "sqlite_storage_executor.h" 34 #include "sqlite_utils.h" 35 #include "tracker_table.h" 36 37 namespace DistributedDB { 38 class SQLiteSingleVerRelationalStorageExecutor : public SQLiteStorageExecutor { 39 public: 40 enum class PutDataMode { 41 SYNC, 42 USER 43 }; 44 enum class MarkFlagOption { 45 DEFAULT, 46 SET_WAIT_COMPENSATED_SYNC 47 }; 48 49 struct UpdateCursorContext { 50 int errCode = E_OK; 51 int cursor; 52 }; 53 54 SQLiteSingleVerRelationalStorageExecutor(sqlite3 *dbHandle, bool writable, DistributedTableMode mode); 55 ~SQLiteSingleVerRelationalStorageExecutor() override = default; 56 57 // Delete the copy and assign constructors 58 DISABLE_COPY_ASSIGN_MOVE(SQLiteSingleVerRelationalStorageExecutor); 59 60 // The parameter "identity" is a hash string that identifies a device 61 int CreateDistributedTable(DistributedTableMode mode, bool isUpgraded, const std::string &identity, 62 TableInfo &table, TableSyncType syncType); 63 64 int UpgradeDistributedTable(const std::string &tableName, DistributedTableMode mode, bool &schemaChanged, 65 RelationalSchemaObject &schema, TableSyncType syncType); 66 67 int StartTransaction(TransactType type); 68 int Commit(); 69 int Rollback(); 70 71 // For Get sync data 72 int GetSyncDataByQuery(std::vector<DataItem> &dataItems, size_t appendLength, const DataSizeSpecInfo &sizeInfo, 73 std::function<int(sqlite3 *, sqlite3_stmt *&, sqlite3_stmt *&, bool &)> getStmt, const TableInfo &tableInfo); 74 75 // operation of meta data 76 int GetKvData(const Key &key, Value &value) const; 77 int PutKvData(const Key &key, const Value &value) const; 78 int DeleteMetaData(const std::vector<Key> &keys) const; 79 int DeleteMetaDataByPrefixKey(const Key &keyPrefix) const; 80 int GetAllMetaKeys(std::vector<Key> &keys) const; 81 82 // For Put sync data 83 int SaveSyncItems(RelationalSyncDataInserter &inserter, bool useTrans = true); 84 85 int CheckDBModeForRelational(); 86 87 int DeleteDistributedDeviceTable(const std::string &device, const std::string &tableName); 88 89 int DeleteDistributedAllDeviceTableLog(const std::string &tableName); 90 91 int DeleteDistributedDeviceTableLog(const std::string &device, const std::string &tableName); 92 93 int DeleteDistributedLogTable(const std::string &tableName); 94 95 int CheckAndCleanDistributedTable(const std::vector<std::string> &tableNames, 96 std::vector<std::string> &missingTables); 97 98 int CreateDistributedDeviceTable(const std::string &device, const TableInfo &baseTbl, const StoreInfo &info); 99 100 int CheckQueryObjectLegal(const TableInfo &table, QueryObject &query, const std::string &schemaVersion); 101 102 int CheckQueryObjectLegal(const QuerySyncObject &query); 103 104 int GetMaxTimestamp(const std::vector<std::string> &tablesName, Timestamp &maxTimestamp) const; 105 106 int ExecuteQueryBySqlStmt(const std::string &sql, const std::vector<std::string> &bindArgs, int packetSize, 107 std::vector<std::string> &colNames, std::vector<RelationalRowData *> &data); 108 109 int SaveSyncDataItems(RelationalSyncDataInserter &inserter); 110 111 int CheckEncryptedOrCorrupted() const; 112 113 int GetExistsDeviceList(std::set<std::string> &devices) const; 114 115 int GetUploadCount(const Timestamp ×tamp, bool isCloudForcePush, bool isCompensatedTask, 116 QuerySyncObject &query, int64_t &count); 117 118 int GetAllUploadCount(const std::vector<Timestamp> ×tampVec, bool isCloudForcePush, bool isCompensatedTask, 119 QuerySyncObject &query, int64_t &count); 120 121 int UpdateCloudLogGid(const CloudSyncData &cloudDataResult, bool ignoreEmptyGid); 122 123 int GetSyncCloudData(const CloudUploadRecorder &uploadRecorder, CloudSyncData &cloudDataResult, 124 SQLiteSingleVerRelationalContinueToken &token); 125 126 int GetSyncCloudGid(QuerySyncObject &query, const SyncTimeRange &syncTimeRange, bool isCloudForcePushStrategy, 127 bool isCompensatedTask, std::vector<std::string> &cloudGid); 128 129 void SetLocalSchema(const RelationalSchemaObject &localSchema); 130 131 int GetInfoByPrimaryKeyOrGid(const TableSchema &tableSchema, const VBucket &vBucket, 132 DataInfoWithLog &dataInfoWithLog, VBucket &assetInfo); 133 134 int PutCloudSyncData(const std::string &tableName, const TableSchema &tableSchema, 135 const TrackerTable &trackerTable, DownloadData &downloadData); 136 137 int FillCloudAssetForDownload(const TableSchema &tableSchema, VBucket &vBucket, bool isDownloadSuccess); 138 int DoCleanInner(ClearMode mode, const std::vector<std::string> &tableNameList, 139 const RelationalSchemaObject &localSchema, std::vector<Asset> &assets, 140 std::vector<std::string> ¬ifyTableList); 141 142 int FillCloudAssetForUpload(OpType opType, const TableSchema &tableSchema, const CloudSyncBatch &data); 143 int FillCloudVersionForUpload(const OpType opType, const CloudSyncData &data); 144 145 int SetLogTriggerStatus(bool status); 146 147 int AnalysisTrackerTable(const TrackerTable &trackerTable, TableInfo &tableInfo); 148 int CreateTrackerTable(const TrackerTable &trackerTable, bool isUpgrade); 149 int GetOrInitTrackerSchemaFromMeta(RelationalSchemaObject &schema); 150 int ExecuteSql(const SqlCondition &condition, std::vector<VBucket> &records); 151 152 int GetClearWaterMarkTables(const std::vector<TableReferenceProperty> &tableReferenceProperty, 153 const RelationalSchemaObject &schema, std::set<std::string> &clearWaterMarkTables); 154 int CreateTempSyncTrigger(const TrackerTable &trackerTable); 155 int GetAndResetServerObserverData(const std::string &tableName, ChangeProperties &changeProperties); 156 int ClearAllTempSyncTrigger(); 157 int CleanTrackerData(const std::string &tableName, int64_t cursor, bool isOnlyTrackTable); 158 int CreateSharedTable(const TableSchema &schema); 159 int DeleteTable(const std::vector<std::string> &tableNames); 160 int UpdateSharedTable(const std::map<std::string, std::vector<Field>> &updateTableNames); 161 int AlterTableName(const std::map<std::string, std::string> &tableNames); 162 int DeleteTableTrigger(const std::string &missTable) const; 163 164 int GetReferenceGid(const std::string &tableName, const CloudSyncBatch &syncBatch, 165 const std::map<std::string, std::vector<TableReferenceProperty>> &tableReference, 166 std::map<int64_t, Entries> &referenceGid); 167 168 int CheckIfExistUserTable(const std::string &tableName); 169 170 void SetLogicDelete(bool isLogicDelete); 171 int RenewTableTrigger(DistributedTableMode mode, const TableInfo &tableInfo, TableSyncType syncType); 172 173 std::pair<int, uint32_t> GetAssetsByGidOrHashKey(const TableSchema &tableSchema, const std::string &gid, 174 const Bytes &hashKey, VBucket &assets); 175 176 int FillHandleWithOpType(const OpType opType, const CloudSyncData &data, bool fillAsset, bool ignoreEmptyGid, 177 const TableSchema &tableSchema); 178 179 void SetIAssetLoader(const std::shared_ptr<IAssetLoader> &loader); 180 181 int CleanResourceForDroppedTable(const std::string &tableName); 182 183 void SetPutDataMode(PutDataMode mode); 184 185 void SetMarkFlagOption(MarkFlagOption option); 186 187 int UpgradedLogForExistedData(TableInfo &tableInfo, bool schemaChanged); 188 189 int UpdateRecordFlag(const std::string &tableName, const std::string &sql, const LogInfo &logInfo); 190 191 void MarkFlagAsUploadFinished(const std::string &tableName, const Key &hashKey, Timestamp timestamp); 192 193 int CleanUploadFinishedFlag(const std::string &tableName); 194 195 int GetWaitCompensatedSyncDataPk(const TableSchema &table, std::vector<VBucket> &data); 196 197 int MarkFlagAsConsistent(const std::string &tableName, const DownloadData &downloadData, 198 const std::set<std::string> &gidFilters); 199 200 int CheckInventoryData(const std::string &tableName); 201 202 int UpdateRecordStatus(const std::string &tableName, const std::string &status, const Key &hashKey); 203 204 void SetUploadConfig(int32_t maxUploadCount, int32_t maxUploadSize); 205 206 int InitCursorToMeta(const std::string &tableName); 207 208 void SetTableSchema(const TableSchema &tableSchema); 209 private: 210 int DoCleanLogs(const std::vector<std::string> &tableNameList, const RelationalSchemaObject &localSchema); 211 212 int DoCleanLogAndData(const std::vector<std::string> &tableNameList, 213 const RelationalSchemaObject &localSchema, std::vector<Asset> &assets); 214 215 int CleanCloudDataOnLogTable(const std::string &logTableName, ClearMode mode); 216 217 int CleanCloudDataAndLogOnUserTable(const std::string &tableName, const std::string &logTableName, 218 const RelationalSchemaObject &localSchema); 219 220 int ChangeCloudDataFlagOnLogTable(const std::string &logTableName); 221 222 int SetDataOnUserTablWithLogicDelete(const std::string &tableName, const std::string &logTableName); 223 224 static void UpdateCursor(sqlite3_context *ctx, int argc, sqlite3_value **argv); 225 226 int CreateFuncUpdateCursor(UpdateCursorContext &context, 227 void(*updateCursorFunc)(sqlite3_context *ctx, int argc, sqlite3_value **argv)) const; 228 229 int GetCursor(const std::string &tableName); 230 231 int SetCursor(const std::string &tableName, int cursor); 232 233 int IncreaseCursorOnAssetData(const std::string &tableName, const std::string &gid); 234 235 int GetCleanCloudDataKeys(const std::string &logTableName, std::vector<int64_t> &dataKeys, 236 bool distinguishCloudFlag); 237 238 int GetCloudAssets(const std::string &tableName, const std::vector<FieldInfo> &fieldInfos, 239 const std::vector<int64_t> &dataKeys, std::vector<Asset> &assets); 240 241 int GetAssetOnTable(const std::string &tableName, const std::string &fieldName, 242 const std::vector<int64_t> &dataKeys, std::vector<Asset> &assets); 243 244 int GetCloudAssetsOnTable(const std::string &tableName, const std::string &fieldName, 245 const std::vector<int64_t> &dataKeys, std::vector<Asset> &assets); 246 247 int GetDataItemForSync(sqlite3_stmt *statement, DataItem &dataItem, bool isGettingDeletedData) const; 248 249 int GetSyncDataPre(const DataItem &dataItem, sqlite3_stmt *queryStmt, DataItem &itemGet); 250 251 int CheckDataConflictDefeated(const DataItem &item, sqlite3_stmt *queryStmt, bool &isDefeated); 252 253 int SaveSyncDataItem(RelationalSyncDataInserter &inserter, SaveSyncDataStmt &saveStmt, DataItem &item); 254 255 int SaveSyncDataItem(const DataItem &dataItem, SaveSyncDataStmt &saveStmt, RelationalSyncDataInserter &inserter, 256 int64_t &rowid); 257 258 int DeleteSyncDataItem(const DataItem &dataItem, RelationalSyncDataInserter &inserter, sqlite3_stmt *&rmDataStmt); 259 260 int GetLogInfoPre(sqlite3_stmt *queryStmt, const DataItem &dataItem, LogInfo &logInfoGet); 261 262 int SaveSyncLog(sqlite3_stmt *statement, sqlite3_stmt *queryStmt, const DataItem &dataItem, int64_t rowid); 263 264 int AlterAuxTableForUpgrade(const TableInfo &oldTableInfo, const TableInfo &newTableInfo); 265 266 int DeleteSyncLog(const DataItem &item, RelationalSyncDataInserter &inserter, sqlite3_stmt *&rmLogStmt); 267 int ProcessMissQueryData(const DataItem &item, RelationalSyncDataInserter &inserter, sqlite3_stmt *&rmDataStmt, 268 sqlite3_stmt *&rmLogStmt); 269 int GetMissQueryData(sqlite3_stmt *fullStmt, DataItem &item); 270 int GetQueryDataAndStepNext(bool isFirstTime, bool isGettingDeletedData, sqlite3_stmt *queryStmt, DataItem &item, 271 Timestamp &queryTime); 272 int GetMissQueryDataAndStepNext(sqlite3_stmt *fullStmt, DataItem &item, Timestamp &missQueryTime); 273 274 void SetTableInfo(const TableInfo &tableInfo); // When put or get sync data, must call the func first. 275 276 int GeneLogInfoForExistedData(sqlite3 *db, const std::string &tableName, const std::string &calPrimaryKeyHash, 277 TableInfo &tableInfo); 278 int CleanExtendAndCursorForDeleteData(const std::string &tableName); 279 280 int GetCloudDataForSync(const CloudUploadRecorder &uploadRecorder, sqlite3_stmt *statement, 281 CloudSyncData &cloudDataResult, uint32_t &stepNum, uint32_t &totalSize); 282 283 int PutVBucketByType(VBucket &vBucket, const Field &field, Type &cloudValue); 284 285 int ExecutePutCloudData(const std::string &tableName, const TableSchema &tableSchema, 286 const TrackerTable &trackerTable, DownloadData &downloadData, std::map<int, int> &statisticMap); 287 288 std::string GetInsertSqlForCloudSync(const TableSchema &tableSchema); 289 290 int GetPrimaryKeyHashValue(const VBucket &vBucket, const TableSchema &tableSchema, std::vector<uint8_t> &hashValue, 291 bool allowEmpty = false); 292 293 int GetQueryLogStatement(const TableSchema &tableSchema, const VBucket &vBucket, const std::string &querySql, 294 const Key &hashKey, sqlite3_stmt *&selectStmt); 295 296 int GetQueryLogSql(const std::string &tableName, const VBucket &vBucket, const std::set<std::string> &pkSet, 297 std::string &querySql); 298 299 int GetQueryInfoSql(const std::string &tableName, const VBucket &vBucket, std::set<std::string> &pkSet, 300 std::vector<Field> &assetFields, std::string &querySql); 301 302 int GetFillDownloadAssetStatement(const std::string &tableName, const VBucket &vBucket, 303 const std::vector<Field> &fields, sqlite3_stmt *&statement); 304 305 int InitFillUploadAssetStatement(OpType opType, const TableSchema &tableSchema, const CloudSyncBatch &data, 306 const int &index, sqlite3_stmt *&statement); 307 308 int GetLogInfoByStatement(sqlite3_stmt *statement, LogInfo &logInfo); 309 310 int GetInfoByStatement(sqlite3_stmt *statement, const std::vector<Field> &assetFields, 311 const std::map<std::string, Field> &pkMap, DataInfoWithLog &dataInfoWithLog, VBucket &assetInfo); 312 313 int InsertCloudData(VBucket &vBucket, const TableSchema &tableSchema, const TrackerTable &trackerTable, 314 int64_t dataKey); 315 316 int InsertLogRecord(const TableSchema &tableSchema, const TrackerTable &trackerTable, VBucket &vBucket); 317 318 int BindOneField(int index, const VBucket &vBucket, const Field &field, sqlite3_stmt *updateStmt); 319 320 int BindValueToUpsertStatement(const VBucket &vBucket, const std::vector<Field> &fields, sqlite3_stmt *upsertStmt); 321 322 int BindStatusSubQueryHashKeyStatement(sqlite3_stmt *insertLogStmt, std::vector<uint8_t> &hashKey); 323 324 int BindHashKeyAndGidToInsertLogStatement(const VBucket &vBucket, const TableSchema &tableSchema, 325 const TrackerTable &trackerTable, sqlite3_stmt *insertLogStmt); 326 327 int BindShareValueToInsertLogStatement(const VBucket &vBucket, const TableSchema &tableSchema, 328 sqlite3_stmt *insertLogStmt); 329 330 int BindValueToInsertLogStatement(VBucket &vBucket, const TableSchema &tableSchema, 331 const TrackerTable &trackerTable, sqlite3_stmt *insertLogStmt); 332 333 std::string GetWhereConditionForDataTable(const std::string &gidStr, const std::set<std::string> &pkSet, 334 const std::string &tableName, bool queryByPk = true); 335 336 int GetUpdateSqlForCloudSync(const std::vector<Field> &updateFields, const TableSchema &tableSchema, 337 const std::string &gidStr, const std::set<std::string> &pkSet, std::string &updateSql); 338 339 int GetUpdateDataTableStatement(const VBucket &vBucket, const TableSchema &tableSchema, sqlite3_stmt *&updateStmt); 340 341 int UpdateCloudData(VBucket &vBucket, const TableSchema &tableSchema); 342 343 int GetUpdateLogRecordStatement(const TableSchema &tableSchema, const VBucket &vBucket, OpType opType, 344 std::vector<std::string> &updateColName, sqlite3_stmt *&updateLogStmt); 345 int AppendUpdateLogRecordWhereSqlCondition(const TableSchema &tableSchema, const VBucket &vBucket, 346 std::string &sql); 347 348 int UpdateLogRecord(const VBucket &vBucket, const TableSchema &tableSchema, OpType opType); 349 350 int BindValueToUpdateLogStatement(const VBucket &vBucket, const TableSchema &tableSchema, 351 const std::vector<std::string> &colNames, bool allowPrimaryKeyEmpty, sqlite3_stmt *updateLogStmt); 352 353 int GetDeleteStatementForCloudSync(const TableSchema &tableSchema, const std::set<std::string> &pkSet, 354 const VBucket &vBucket, sqlite3_stmt *&deleteStmt); 355 356 int DeleteCloudData(const std::string &tableName, const VBucket &vBucket, const TableSchema &tableSchema, 357 const TrackerTable &trackerTable); 358 359 int OnlyUpdateLogTable(const VBucket &vBucket, const TableSchema &tableSchema, OpType opType); 360 361 int IsTableOnceDropped(const std::string &tableName, int execCode, bool &onceDropped); 362 363 int BindUpdateVersionStatement(const VBucket &vBucket, const Bytes &hashKey, sqlite3_stmt *&stmt); 364 int DoCleanShareTableDataAndLog(const std::vector<std::string> &tableNameList); 365 366 int GetReferenceGidInner(const std::string &sourceTable, const std::string &targetTable, 367 const CloudSyncBatch &syncBatch, const std::vector<TableReferenceProperty> &targetTableReference, 368 std::map<int64_t, Entries> &referenceGid); 369 370 int GetReferenceGidByStmt(sqlite3_stmt *statement, const CloudSyncBatch &syncBatch, 371 const std::string &targetTable, std::map<int64_t, Entries> &referenceGid); 372 373 static std::string GetReferenceGidSql(const std::string &sourceTable, const std::string &targetTable, 374 const std::vector<std::string> &sourceFields, const std::vector<std::string> &targetFields); 375 376 static std::pair<std::vector<std::string>, std::vector<std::string>> SplitReferenceByField( 377 const std::vector<TableReferenceProperty> &targetTableReference); 378 379 int BindStmtWithCloudGid(const CloudSyncData &cloudDataResult, bool ignoreEmptyGid, sqlite3_stmt *&stmt); 380 381 std::string GetCloudDeleteSql(const std::string &logTable); 382 383 int RemoveDataAndLog(const std::string &tableName, int64_t dataKey); 384 385 int64_t GetLocalDataKey(size_t index, const DownloadData &downloadData); 386 387 int BindStmtWithCloudGidInner(const std::string &gid, int64_t rowid, 388 sqlite3_stmt *&stmt, int &fillGidCount); 389 390 int DoCleanAssetId(const std::string &tableName, const RelationalSchemaObject &localSchema); 391 392 int CleanAssetId(const std::string &tableName, const std::vector<FieldInfo> &fieldInfos, 393 const std::vector<int64_t> &dataKeys); 394 395 int UpdateAssetIdOnUserTable(const std::string &tableName, const std::string &fieldName, 396 const std::vector<int64_t> &dataKeys, std::vector<Asset> &assets); 397 398 int GetAssetsAndUpdateAssetsId(const std::string &tableName, const std::string &fieldName, 399 const std::vector<int64_t> &dataKeys); 400 401 int CleanAssetsIdOnUserTable(const std::string &tableName, const std::string &fieldName, const int64_t rowId, 402 const std::vector<uint8_t> &assetsValue); 403 404 int InitGetAssetStmt(const std::string &sql, const std::string &gid, const Bytes &hashKey, 405 sqlite3_stmt *&stmt); 406 407 int GetAssetsByRowId(sqlite3_stmt *&selectStmt, Assets &assets); 408 409 int ExecuteFillDownloadAssetStatement(sqlite3_stmt *&stmt, int beginIndex, const std::string &cloudGid); 410 411 int CleanDownloadChangedAssets(const VBucket &vBucket, const AssetOperationUtils::RecordAssetOpType &assetOpType); 412 413 int GetAndBindFillUploadAssetStatement(const std::string &tableName, const VBucket &assets, 414 sqlite3_stmt *&statement); 415 416 int OnlyUpdateAssetId(const std::string &tableName, const TableSchema &tableSchema, const VBucket &vBucket, 417 int64_t dataKey, OpType opType); 418 419 void UpdateLocalAssetId(const VBucket &vBucket, const std::string &fieldName, Asset &asset); 420 421 void UpdateLocalAssetsId(const VBucket &vBucket, const std::string &fieldName, Assets &assets); 422 423 void UpdateLocalAssetsIdInner(const Assets &cloudAssets, Assets &assets); 424 425 int BindAssetToBlobStatement(const Asset &asset, int index, sqlite3_stmt *&stmt); 426 427 int BindAssetsToBlobStatement(const Assets &assets, int index, sqlite3_stmt *&stmt); 428 429 int GetAssetOnTableInner(sqlite3_stmt *&stmt, Asset &asset); 430 431 int GetAssetOnTable(const std::string &tableName, const std::string &fieldName, const int64_t dataKey, 432 Asset &asset); 433 434 int GetAssetsOnTableInner(sqlite3_stmt *&stmt, Assets &assets); 435 436 int GetAssetsOnTable(const std::string &tableName, const std::string &fieldName, const int64_t dataKey, 437 Assets &assets); 438 439 int BindAssetFiledToBlobStatement(const TableSchema &tableSchema, const std::vector<Asset> &assetOfOneRecord, 440 const std::vector<Assets> &assetsOfOneRecord, sqlite3_stmt *&stmt); 441 442 int UpdateAssetsIdForOneRecord(const TableSchema &tableSchema, const std::string &sql, 443 const std::vector<Asset> &assetOfOneRecord, const std::vector<Assets> &assetsOfOneRecord); 444 445 int UpdateAssetId(const TableSchema &tableSchema, int64_t dataKey, const VBucket &vBucket); 446 447 int64_t GetDataFlag(); 448 449 std::string GetUpdateDataFlagSql(); 450 451 std::string GetDev(); 452 453 std::vector<Field> GetUpdateField(const VBucket &vBucket, const TableSchema &tableSchema); 454 455 int GetRecordFromStmt(sqlite3_stmt *stmt, const std::vector<Field> &fields, int startIndex, VBucket &record); 456 457 int FillCloudVersionForUpload(const std::string &tableName, const CloudSyncBatch &batchData); 458 459 int QueryCount(const std::string &tableName, int64_t &count); 460 461 int GetUploadCountInner(const Timestamp ×tamp, SqliteQueryHelper &helper, std::string &sql, int64_t &count); 462 463 int LogicDeleteCloudData(const std::string &tableName, const VBucket &vBucket, 464 const TableSchema &tableSchema, const TrackerTable &trackerTable); 465 466 static constexpr const char *CONSISTENT_FLAG = "0x20"; 467 static constexpr const char *UPDATE_FLAG_CLOUD = "flag = flag & 0x20"; 468 static constexpr const char *UPDATE_FLAG_WAIT_COMPENSATED_SYNC = "flag = flag | 0x10"; 469 static constexpr const char *FLAG_IS_WAIT_COMPENSATED_SYNC = 470 "(a.flag & 0x10 != 0 and a.status = 0) or a.status = 1"; 471 472 std::string baseTblName_; 473 TableInfo table_; // Always operating table, user table when get, device table when put. 474 TableSchema tableSchema_; // for cloud table 475 RelationalSchemaObject localSchema_; 476 477 DistributedTableMode mode_; 478 479 std::map<int32_t, std::function<int(int, const VBucket &, const Field &, sqlite3_stmt *)>> bindCloudFieldFuncMap_; 480 std::map<int32_t, std::function<int(const VBucket &, const Field &, std::vector<uint8_t> &)>> toVectorFuncMap_; 481 482 std::atomic<bool> isLogicDelete_; 483 std::shared_ptr<IAssetLoader> assetLoader_; 484 485 PutDataMode putDataMode_; 486 MarkFlagOption markFlagOption_; 487 488 std::atomic<int32_t> maxUploadCount_; 489 std::atomic<int32_t> maxUploadSize_; 490 }; 491 } // namespace DistributedDB 492 #endif 493 #endif // SQLITE_SINGLE_VER_RELATIONAL_STORAGE_EXECUTOR_H