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

L
Liu Jicong 已提交
16
#include "cJSON.h"
L
Liu Jicong 已提交
17 18
#include "os.h"
#include "taoserror.h"
L
Liu Jicong 已提交
19
#include "tref.h"
L
Liu Jicong 已提交
20 21
#include "walInt.h"

L
Liu Jicong 已提交
22
int64_t FORCE_INLINE walGetFirstVer(SWal* pWal) { return pWal->vers.firstVer; }
L
Liu Jicong 已提交
23

L
Liu Jicong 已提交
24
int64_t FORCE_INLINE walGetSnaphostVer(SWal* pWal) { return pWal->vers.snapshotVer; }
L
Liu Jicong 已提交
25

L
Liu Jicong 已提交
26
int64_t FORCE_INLINE walGetLastVer(SWal* pWal) { return pWal->vers.lastVer; }
L
Liu Jicong 已提交
27

L
Liu Jicong 已提交
28
static FORCE_INLINE int walBuildMetaName(SWal* pWal, int metaVer, char* buf) {
L
Liu Jicong 已提交
29 30 31
  return sprintf(buf, "%s/meta-ver%d", pWal->path, metaVer);
}

L
Liu Jicong 已提交
32 33 34 35
void* tmemmem(char* haystack, int hlen, char* needle, int nlen) {
  char* limit;

  if (nlen == 0 || hlen < nlen) {
L
Liu Jicong 已提交
36
    return NULL;
L
Liu Jicong 已提交
37 38 39
  }

  limit = haystack + hlen - nlen + 1;
L
Liu Jicong 已提交
40
  while ((haystack = (char*)memchr(haystack, needle[0], limit - haystack)) != NULL) {
L
Liu Jicong 已提交
41 42 43 44 45 46 47 48
    if (memcmp(haystack, needle, nlen) == 0) {
      return haystack;
    }
    haystack++;
  }
  return NULL;
}

L
Liu Jicong 已提交
49
static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) {
L
Liu Jicong 已提交
50 51 52
  ASSERT(pWal->fileInfoSet != NULL);
  int sz = taosArrayGetSize(pWal->fileInfoSet);
  ASSERT(sz > 0);
L
Liu Jicong 已提交
53
#if 0
L
Liu Jicong 已提交
54 55 56
  for (int i = 0; i < sz; i++) {
    SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, i);
  }
L
Liu Jicong 已提交
57 58
#endif

L
Liu Jicong 已提交
59 60
  SWalFileInfo* pLastFileInfo = taosArrayGet(pWal->fileInfoSet, sz - 1);
  char          fnameStr[WAL_FILE_LEN];
L
Liu Jicong 已提交
61 62
  walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr);

63 64 65 66
  int64_t file_size = 0;
  taosStatFile(fnameStr, &file_size, NULL);
  int readSize = TMIN(WAL_MAX_SIZE + 2, file_size);
  pLastFileInfo->fileSize = file_size;
L
Liu Jicong 已提交
67

68 69
  TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ);
  if (pFile == NULL) {
L
Liu Jicong 已提交
70 71 72 73 74 75
    terrno = TAOS_SYSTEM_ERROR(errno);
    return -1;
  }

  uint64_t magic = WAL_MAGIC;

wafwerar's avatar
wafwerar 已提交
76
  char* buf = taosMemoryMalloc(readSize + 5);
L
Liu Jicong 已提交
77
  if (buf == NULL) {
78
    taosCloseFile(&pFile);
L
Liu Jicong 已提交
79 80 81 82
    terrno = TSDB_CODE_WAL_OUT_OF_MEMORY;
    return -1;
  }

83 84
  taosLSeekFile(pFile, -readSize, SEEK_END);
  if (readSize != taosReadFile(pFile, buf, readSize)) {
wafwerar's avatar
wafwerar 已提交
85
    taosMemoryFree(buf);
86
    taosCloseFile(&pFile);
L
Liu Jicong 已提交
87 88 89
    terrno = TAOS_SYSTEM_ERROR(errno);
    return -1;
  }
L
Liu Jicong 已提交
90

L
Liu Jicong 已提交
91 92
  char* haystack = buf;
  char* found = NULL;
L
Liu Jicong 已提交
93 94
  char* candidate;
  while ((candidate = tmemmem(haystack, readSize - (haystack - buf), (char*)&magic, sizeof(uint64_t))) != NULL) {
L
Liu Jicong 已提交
95
    // read and validate
L
Liu Jicong 已提交
96
    SWalHead* logContent = (SWalHead*)candidate;
L
Liu Jicong 已提交
97
    if (walValidHeadCksum(logContent) == 0 && walValidBodyCksum(logContent) == 0) {
L
Liu Jicong 已提交
98 99 100 101 102
      found = candidate;
    }
    haystack = candidate + 1;
  }
  if (found == buf) {
L
Liu Jicong 已提交
103
    SWalHead* logContent = (SWalHead*)found;
L
Liu Jicong 已提交
104 105
    if (walValidHeadCksum(logContent) != 0 || walValidBodyCksum(logContent) != 0) {
      // file has to be deleted
wafwerar's avatar
wafwerar 已提交
106
      taosMemoryFree(buf);
107
      taosCloseFile(&pFile);
L
Liu Jicong 已提交
108 109
      terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
      return -1;
L
Liu Jicong 已提交
110 111
    }
  }
112
  taosCloseFile(&pFile);
L
Liu Jicong 已提交
113
  SWalHead* lastEntry = (SWalHead*)found;
L
Liu Jicong 已提交
114 115 116 117

  return lastEntry->head.version;
}

L
Liu Jicong 已提交
118 119 120 121
int walCheckAndRepairMeta(SWal* pWal) {
  // load log files, get first/snapshot/last version info
  const char* logPattern = "^[0-9]+.log$";
  const char* idxPattern = "^[0-9]+.idx$";
L
Liu Jicong 已提交
122 123
  regex_t     logRegPattern;
  regex_t     idxRegPattern;
L
Liu Jicong 已提交
124
  SArray*     pLogInfoArray = taosArrayInit(8, sizeof(SWalFileInfo));
L
Liu Jicong 已提交
125 126 127

  regcomp(&logRegPattern, logPattern, REG_EXTENDED);
  regcomp(&idxRegPattern, idxPattern, REG_EXTENDED);
L
Liu Jicong 已提交
128

wafwerar's avatar
wafwerar 已提交
129 130
  TdDirPtr pDir = taosOpenDir(pWal->path);
  if (pDir == NULL) {
L
Liu Jicong 已提交
131 132 133 134
    wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, strerror(errno));
    return -1;
  }

L
Liu Jicong 已提交
135
  // scan log files and build new meta
wafwerar's avatar
wafwerar 已提交
136 137 138
  TdDirEntryPtr pDirEntry;
  while ((pDirEntry = taosReadDir(pDir)) != NULL) {
    char* name = taosDirEntryBaseName(taosGetDirEntryName(pDirEntry));
L
Liu Jicong 已提交
139 140
    int   code = regexec(&logRegPattern, name, 0, NULL, 0);
    if (code == 0) {
L
Liu Jicong 已提交
141 142 143 144
      SWalFileInfo fileInfo;
      memset(&fileInfo, -1, sizeof(SWalFileInfo));
      sscanf(name, "%" PRId64 ".log", &fileInfo.firstVer);
      taosArrayPush(pLogInfoArray, &fileInfo);
L
Liu Jicong 已提交
145 146 147
    }
  }

wafwerar's avatar
wafwerar 已提交
148
  taosCloseDir(pDir);
L
Liu Jicong 已提交
149 150 151 152 153 154 155 156 157
  regfree(&logRegPattern);
  regfree(&idxRegPattern);

  taosArraySort(pLogInfoArray, compareWalFileInfo);
  int oldSz = 0;
  if (pWal->fileInfoSet) {
    oldSz = taosArrayGetSize(pWal->fileInfoSet);
  }
  int newSz = taosArrayGetSize(pLogInfoArray);
L
Liu Jicong 已提交
158 159

  if (oldSz > newSz) {
L
Liu Jicong 已提交
160
    taosArrayPopFrontBatch(pWal->fileInfoSet, oldSz - newSz);
L
Liu Jicong 已提交
161
  } else if (oldSz < newSz) {
L
Liu Jicong 已提交
162
    for (int i = oldSz; i < newSz; i++) {
L
Liu Jicong 已提交
163
      SWalFileInfo* pFileInfo = taosArrayGet(pLogInfoArray, i);
L
Liu Jicong 已提交
164 165
      taosArrayPush(pWal->fileInfoSet, pFileInfo);
    }
L
Liu Jicong 已提交
166
  }
L
Liu Jicong 已提交
167
  taosArrayDestroy(pLogInfoArray);
L
Liu Jicong 已提交
168

L
Liu Jicong 已提交
169 170 171 172
  pWal->writeCur = newSz - 1;
  if (newSz > 0) {
    pWal->vers.firstVer = ((SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, 0))->firstVer;

L
Liu Jicong 已提交
173 174
    SWalFileInfo* pLastFileInfo = taosArrayGet(pWal->fileInfoSet, newSz - 1);
    char          fnameStr[WAL_FILE_LEN];
L
Liu Jicong 已提交
175
    walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr);
176 177
    int64_t file_size = 0;
    taosStatFile(fnameStr, &file_size, NULL);
L
Liu Jicong 已提交
178

179 180
    if (oldSz != newSz || pLastFileInfo->fileSize != file_size) {
      pLastFileInfo->fileSize = file_size;
L
Liu Jicong 已提交
181 182 183 184 185 186 187 188
      pWal->vers.lastVer = walScanLogGetLastVer(pWal);
      ((SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet))->lastVer = pWal->vers.lastVer;
      ASSERT(pWal->vers.lastVer != -1);

      int code = walSaveMeta(pWal);
      if (code < 0) {
        taosArrayDestroy(pLogInfoArray);
        return -1;
L
Liu Jicong 已提交
189 190 191 192
      }
    }
  }

L
Liu Jicong 已提交
193 194
  // TODO: set fileSize and lastVer if necessary

L
Liu Jicong 已提交
195 196 197 198
  return 0;
}

int walCheckAndRepairIdx(SWal* pWal) {
L
Liu Jicong 已提交
199 200 201 202
  // TODO: iterate all log files
  // if idx not found, scan log and write idx
  // if found, check complete by first and last entry of each idx file
  // if idx incomplete, binary search last valid entry, and then build other part
L
Liu Jicong 已提交
203 204 205
  return 0;
}

L
Liu Jicong 已提交
206 207 208 209
int walRollFileInfo(SWal* pWal) {
  int64_t ts = taosGetTimestampSec();

  SArray* pArray = pWal->fileInfoSet;
L
Liu Jicong 已提交
210
  if (taosArrayGetSize(pArray) != 0) {
L
Liu Jicong 已提交
211
    SWalFileInfo* pInfo = taosArrayGetLast(pArray);
L
Liu Jicong 已提交
212
    pInfo->lastVer = pWal->vers.lastVer;
L
Liu Jicong 已提交
213 214 215
    pInfo->closeTs = ts;
  }

L
Liu Jicong 已提交
216
  // TODO: change to emplace back
wafwerar's avatar
wafwerar 已提交
217
  SWalFileInfo* pNewInfo = taosMemoryMalloc(sizeof(SWalFileInfo));
L
Liu Jicong 已提交
218
  if (pNewInfo == NULL) {
L
Liu Jicong 已提交
219
    terrno = TSDB_CODE_WAL_OUT_OF_MEMORY;
L
Liu Jicong 已提交
220 221
    return -1;
  }
L
Liu Jicong 已提交
222
  pNewInfo->firstVer = pWal->vers.lastVer + 1;
L
Liu Jicong 已提交
223 224 225 226
  pNewInfo->lastVer = -1;
  pNewInfo->createTs = ts;
  pNewInfo->closeTs = -1;
  pNewInfo->fileSize = 0;
L
Liu Jicong 已提交
227
  taosArrayPush(pArray, pNewInfo);
wafwerar's avatar
wafwerar 已提交
228
  taosMemoryFree(pNewInfo);
L
Liu Jicong 已提交
229 230 231
  return 0;
}

232
char* walMetaSerialize(SWal* pWal) {
L
Liu Jicong 已提交
233
  char buf[30];
L
Liu Jicong 已提交
234
  ASSERT(pWal->fileInfoSet);
L
Liu Jicong 已提交
235
  int    sz = pWal->fileInfoSet->size;
236 237 238 239
  cJSON* pRoot = cJSON_CreateObject();
  cJSON* pMeta = cJSON_CreateObject();
  cJSON* pFiles = cJSON_CreateArray();
  cJSON* pField;
L
Liu Jicong 已提交
240
  if (pRoot == NULL || pMeta == NULL || pFiles == NULL) {
L
Liu Jicong 已提交
241
    if (pRoot) {
L
Liu Jicong 已提交
242 243
      cJSON_Delete(pRoot);
    }
L
Liu Jicong 已提交
244
    if (pMeta) {
L
Liu Jicong 已提交
245 246
      cJSON_Delete(pMeta);
    }
L
Liu Jicong 已提交
247
    if (pFiles) {
L
Liu Jicong 已提交
248 249 250
      cJSON_Delete(pFiles);
    }
    terrno = TSDB_CODE_WAL_OUT_OF_MEMORY;
L
Liu Jicong 已提交
251 252
    return NULL;
  }
253
  cJSON_AddItemToObject(pRoot, "meta", pMeta);
L
Liu Jicong 已提交
254
  sprintf(buf, "%" PRId64, pWal->vers.firstVer);
255
  cJSON_AddStringToObject(pMeta, "firstVer", buf);
L
Liu Jicong 已提交
256
  sprintf(buf, "%" PRId64, pWal->vers.snapshotVer);
257
  cJSON_AddStringToObject(pMeta, "snapshotVer", buf);
L
Liu Jicong 已提交
258
  sprintf(buf, "%" PRId64, pWal->vers.commitVer);
259
  cJSON_AddStringToObject(pMeta, "commitVer", buf);
L
Liu Jicong 已提交
260
  sprintf(buf, "%" PRId64, pWal->vers.lastVer);
261 262 263
  cJSON_AddStringToObject(pMeta, "lastVer", buf);

  cJSON_AddItemToObject(pRoot, "files", pFiles);
L
Liu Jicong 已提交
264
  SWalFileInfo* pData = pWal->fileInfoSet->pData;
L
Liu Jicong 已提交
265
  for (int i = 0; i < sz; i++) {
L
Liu Jicong 已提交
266
    SWalFileInfo* pInfo = &pData[i];
267
    cJSON_AddItemToArray(pFiles, pField = cJSON_CreateObject());
L
Liu Jicong 已提交
268
    if (pField == NULL) {
269
      cJSON_Delete(pRoot);
L
Liu Jicong 已提交
270 271
      return NULL;
    }
L
Liu Jicong 已提交
272 273
    // cjson only support int32_t or double
    // string are used to prohibit the loss of precision
274 275 276 277 278 279 280 281 282 283
    sprintf(buf, "%" PRId64, pInfo->firstVer);
    cJSON_AddStringToObject(pField, "firstVer", buf);
    sprintf(buf, "%" PRId64, pInfo->lastVer);
    cJSON_AddStringToObject(pField, "lastVer", buf);
    sprintf(buf, "%" PRId64, pInfo->createTs);
    cJSON_AddStringToObject(pField, "createTs", buf);
    sprintf(buf, "%" PRId64, pInfo->closeTs);
    cJSON_AddStringToObject(pField, "closeTs", buf);
    sprintf(buf, "%" PRId64, pInfo->fileSize);
    cJSON_AddStringToObject(pField, "fileSize", buf);
L
Liu Jicong 已提交
284
  }
L
Liu Jicong 已提交
285 286 287
  char* serialized = cJSON_Print(pRoot);
  cJSON_Delete(pRoot);
  return serialized;
L
Liu Jicong 已提交
288 289
}

290 291 292 293 294 295
int walMetaDeserialize(SWal* pWal, const char* bytes) {
  ASSERT(taosArrayGetSize(pWal->fileInfoSet) == 0);
  cJSON *pRoot, *pMeta, *pFiles, *pInfoJson, *pField;
  pRoot = cJSON_Parse(bytes);
  pMeta = cJSON_GetObjectItem(pRoot, "meta");
  pField = cJSON_GetObjectItem(pMeta, "firstVer");
L
Liu Jicong 已提交
296
  pWal->vers.firstVer = atoll(cJSON_GetStringValue(pField));
297
  pField = cJSON_GetObjectItem(pMeta, "snapshotVer");
L
Liu Jicong 已提交
298
  pWal->vers.snapshotVer = atoll(cJSON_GetStringValue(pField));
299
  pField = cJSON_GetObjectItem(pMeta, "commitVer");
L
Liu Jicong 已提交
300
  pWal->vers.commitVer = atoll(cJSON_GetStringValue(pField));
301
  pField = cJSON_GetObjectItem(pMeta, "lastVer");
L
Liu Jicong 已提交
302
  pWal->vers.lastVer = atoll(cJSON_GetStringValue(pField));
303 304 305

  pFiles = cJSON_GetObjectItem(pRoot, "files");
  int sz = cJSON_GetArraySize(pFiles);
L
Liu Jicong 已提交
306
  // deserialize
L
Liu Jicong 已提交
307 308
  SArray* pArray = pWal->fileInfoSet;
  taosArrayEnsureCap(pArray, sz);
L
Liu Jicong 已提交
309
  SWalFileInfo* pData = pArray->pData;
L
Liu Jicong 已提交
310
  for (int i = 0; i < sz; i++) {
L
Liu Jicong 已提交
311 312
    cJSON*        pInfoJson = cJSON_GetArrayItem(pFiles, i);
    SWalFileInfo* pInfo = &pData[i];
L
Liu Jicong 已提交
313 314 315 316 317 318 319 320 321 322 323 324
    pField = cJSON_GetObjectItem(pInfoJson, "firstVer");
    pInfo->firstVer = atoll(cJSON_GetStringValue(pField));
    pField = cJSON_GetObjectItem(pInfoJson, "lastVer");
    pInfo->lastVer = atoll(cJSON_GetStringValue(pField));
    pField = cJSON_GetObjectItem(pInfoJson, "createTs");
    pInfo->createTs = atoll(cJSON_GetStringValue(pField));
    pField = cJSON_GetObjectItem(pInfoJson, "closeTs");
    pInfo->closeTs = atoll(cJSON_GetStringValue(pField));
    pField = cJSON_GetObjectItem(pInfoJson, "fileSize");
    pInfo->fileSize = atoll(cJSON_GetStringValue(pField));
  }
  taosArraySetSize(pArray, sz);
325
  pWal->fileInfoSet = pArray;
L
Liu Jicong 已提交
326
  pWal->writeCur = sz - 1;
L
Liu Jicong 已提交
327
  cJSON_Delete(pRoot);
328
  return 0;
L
Liu Jicong 已提交
329 330 331
}

static int walFindCurMetaVer(SWal* pWal) {
L
Liu Jicong 已提交
332 333
  const char* pattern = "^meta-ver[0-9]+$";
  regex_t     walMetaRegexPattern;
L
Liu Jicong 已提交
334 335
  regcomp(&walMetaRegexPattern, pattern, REG_EXTENDED);

wafwerar's avatar
wafwerar 已提交
336 337
  TdDirPtr pDir = taosOpenDir(pWal->path);
  if (pDir == NULL) {
L
Liu Jicong 已提交
338
    wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, strerror(errno));
L
Liu Jicong 已提交
339 340 341
    return -1;
  }

wafwerar's avatar
wafwerar 已提交
342
  TdDirEntryPtr pDirEntry;
L
Liu Jicong 已提交
343

L
Liu Jicong 已提交
344
  // find existing meta-ver[x].json
L
Liu Jicong 已提交
345
  int metaVer = -1;
wafwerar's avatar
wafwerar 已提交
346 347
  while ((pDirEntry = taosReadDir(pDir)) != NULL) {
    char* name = taosDirEntryBaseName(taosGetDirEntryName(pDirEntry));
L
Liu Jicong 已提交
348 349
    int   code = regexec(&walMetaRegexPattern, name, 0, NULL, 0);
    if (code == 0) {
L
Liu Jicong 已提交
350 351 352 353
      sscanf(name, "meta-ver%d", &metaVer);
      break;
    }
  }
wafwerar's avatar
wafwerar 已提交
354
  taosCloseDir(pDir);
L
Liu Jicong 已提交
355
  regfree(&walMetaRegexPattern);
L
Liu Jicong 已提交
356 357 358
  return metaVer;
}

L
Liu Jicong 已提交
359
int walSaveMeta(SWal* pWal) {
L
Liu Jicong 已提交
360
  int  metaVer = walFindCurMetaVer(pWal);
L
Liu Jicong 已提交
361
  char fnameStr[WAL_FILE_LEN];
L
Liu Jicong 已提交
362
  walBuildMetaName(pWal, metaVer + 1, fnameStr);
363 364
  TdFilePtr pMataFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE);
  if (pMataFile == NULL) {
L
Liu Jicong 已提交
365 366
    return -1;
  }
367
  char* serialized = walMetaSerialize(pWal);
L
Liu Jicong 已提交
368
  int   len = strlen(serialized);
369
  if (len != taosWriteFile(pMataFile, serialized, len)) {
L
Liu Jicong 已提交
370
    // TODO:clean file
L
Liu Jicong 已提交
371 372
    return -1;
  }
L
Liu Jicong 已提交
373

374
  taosCloseFile(&pMataFile);
L
Liu Jicong 已提交
375 376
  // delete old file
  if (metaVer > -1) {
L
Liu Jicong 已提交
377
    walBuildMetaName(pWal, metaVer, fnameStr);
378
    taosRemoveFile(fnameStr);
L
Liu Jicong 已提交
379
  }
wafwerar's avatar
wafwerar 已提交
380
  taosMemoryFree(serialized);
L
Liu Jicong 已提交
381 382 383
  return 0;
}

L
Liu Jicong 已提交
384
int walLoadMeta(SWal* pWal) {
L
Liu Jicong 已提交
385
  ASSERT(pWal->fileInfoSet->size == 0);
L
Liu Jicong 已提交
386
  // find existing meta file
L
Liu Jicong 已提交
387
  int metaVer = walFindCurMetaVer(pWal);
L
Liu Jicong 已提交
388
  if (metaVer == -1) {
L
Liu Jicong 已提交
389
    return -1;
L
Liu Jicong 已提交
390 391 392
  }
  char fnameStr[WAL_FILE_LEN];
  walBuildMetaName(pWal, metaVer, fnameStr);
L
Liu Jicong 已提交
393
  // read metafile
394 395 396
  int64_t file_size = 0;
  taosStatFile(fnameStr, &file_size, NULL);
  int   size = (int)file_size;
wafwerar's avatar
wafwerar 已提交
397
  char* buf = taosMemoryMalloc(size + 5);
L
Liu Jicong 已提交
398
  if (buf == NULL) {
L
Liu Jicong 已提交
399
    terrno = TSDB_CODE_WAL_OUT_OF_MEMORY;
L
Liu Jicong 已提交
400 401
    return -1;
  }
L
Liu Jicong 已提交
402
  memset(buf, 0, size + 5);
403 404
  TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ);
  if (pFile == NULL) {
L
Liu Jicong 已提交
405 406 407
    terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
    return -1;
  }
408
  if (taosReadFile(pFile, buf, size) != size) {
L
Liu Jicong 已提交
409
    terrno = TAOS_SYSTEM_ERROR(errno);
410
    taosCloseFile(&pFile);
wafwerar's avatar
wafwerar 已提交
411
    taosMemoryFree(buf);
L
Liu Jicong 已提交
412 413
    return -1;
  }
L
Liu Jicong 已提交
414
  // load into fileInfoSet
415
  int code = walMetaDeserialize(pWal, buf);
416
  taosCloseFile(&pFile);
wafwerar's avatar
wafwerar 已提交
417
  taosMemoryFree(buf);
L
Liu Jicong 已提交
418
  return code;
L
Liu Jicong 已提交
419
}