walWrite.c 11.8 KB
Newer Older
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
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/>.
 */

S
Shengliang Guan 已提交
16
#define _DEFAULT_SOURCE
L
Liu Jicong 已提交
17

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
18
#include "os.h"
S
Shengliang Guan 已提交
19
#include "taoserror.h"
20
#include "tchecksum.h"
S
TD-1895  
Shengliang Guan 已提交
21
#include "tfile.h"
S
Shengliang Guan 已提交
22
#include "walInt.h"
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
23

L
Liu Jicong 已提交
24 25 26 27 28 29 30 31 32 33 34 35
int32_t walCommit(SWal *pWal, int64_t ver) {
  return 0;
}

int32_t walRollback(SWal *pWal, int64_t ver) {
  return 0;
}

int32_t walTakeSnapshot(SWal *pWal, int64_t ver) {
  return 0;
}

L
Liu Jicong 已提交
36
#if 0
S
TD-1882  
Shengliang Guan 已提交
37
static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, char *name, int64_t fileId);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
38

S
Shengliang Guan 已提交
39
int32_t walRenew(void *handle) {
40
  if (handle == NULL) return 0;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
41

S
TD-1846  
Shengliang Guan 已提交
42 43
  SWal *  pWal = handle;
  int32_t code = 0;
44

L
Liu Jicong 已提交
45 46 47 48
  /*if (pWal->stop) {*/
    /*wDebug("vgId:%d, do not create a new wal file", pWal->vgId);*/
    /*return 0;*/
  /*}*/
S
TD-1894  
Shengliang Guan 已提交
49

50 51
  pthread_mutex_lock(&pWal->mutex);

L
Liu Jicong 已提交
52 53 54
  if (tfValid(pWal->logTfd)) {
    tfClose(pWal->logTfd);
    wDebug("vgId:%d, file:%s, it is closed while renew", pWal->vgId, pWal->logName);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
55 56
  }

L
Liu Jicong 已提交
57 58 59 60 61 62
  /*if (pWal->keep == TAOS_WAL_KEEP) {*/
    /*pWal->fileId = 0;*/
  /*} else {*/
    /*if (walGetNewFile(pWal, &pWal->fileId) != 0) pWal->fileId = 0;*/
    /*pWal->fileId++;*/
  /*}*/
63

L
Liu Jicong 已提交
64 65
  snprintf(pWal->logName, sizeof(pWal->logName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->curFileId);
  pWal->logTfd = tfOpenCreateWrite(pWal->logName);
66

L
Liu Jicong 已提交
67
  if (!tfValid(pWal->logTfd)) {
S
TD-1846  
Shengliang Guan 已提交
68
    code = TAOS_SYSTEM_ERROR(errno);
L
Liu Jicong 已提交
69
    wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->logName, strerror(errno));
70
  } else {
L
Liu Jicong 已提交
71
    wDebug("vgId:%d, file:%s, it is created and open while renew", pWal->vgId, pWal->logName);
S
TD-1846  
Shengliang Guan 已提交
72
  }
73

S
TD-1949  
Shengliang Guan 已提交
74 75 76 77 78
  pthread_mutex_unlock(&pWal->mutex);

  return code;
}

S
TD-1949  
Shengliang Guan 已提交
79
void walRemoveOneOldFile(void *handle) {
S
TD-1949  
Shengliang Guan 已提交
80 81
  SWal *pWal = handle;
  if (pWal == NULL) return;
L
Liu Jicong 已提交
82
  /*if (pWal->keep == TAOS_WAL_KEEP) return;*/
L
Liu Jicong 已提交
83
  if (!tfValid(pWal->logTfd)) return;
S
TD-1949  
Shengliang Guan 已提交
84 85 86 87 88

  pthread_mutex_lock(&pWal->mutex);

  // remove the oldest wal file
  int64_t oldFileId = -1;
L
Liu Jicong 已提交
89
  if (walGetOldFile(pWal, pWal->curFileId, WAL_FILE_NUM, &oldFileId) == 0) {
S
TD-1949  
Shengliang Guan 已提交
90 91 92 93 94 95 96
    char walName[WAL_FILE_LEN] = {0};
    snprintf(walName, sizeof(walName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, oldFileId);

    if (remove(walName) < 0) {
      wError("vgId:%d, file:%s, failed to remove since %s", pWal->vgId, walName, strerror(errno));
    } else {
      wInfo("vgId:%d, file:%s, it is removed", pWal->vgId, walName);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
97
    }
S
TD-1652  
Shengliang Guan 已提交
98 99
  }

100
  pthread_mutex_unlock(&pWal->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
101 102
}

S
TD-1949  
Shengliang Guan 已提交
103 104 105 106 107
void walRemoveAllOldFiles(void *handle) {
  if (handle == NULL) return;

  SWal *  pWal = handle;
  int64_t fileId = -1;
S
TD-2087  
Shengliang Guan 已提交
108 109

  pthread_mutex_lock(&pWal->mutex);
S
Shengliang Guan 已提交
110
  
L
Liu Jicong 已提交
111 112
  tfClose(pWal->logTfd);
  wDebug("vgId:%d, file:%s, it is closed before remove all wals", pWal->vgId, pWal->logName);
S
Shengliang Guan 已提交
113

S
TD-1949  
Shengliang Guan 已提交
114
  while (walGetNextFile(pWal, &fileId) >= 0) {
L
Liu Jicong 已提交
115
    snprintf(pWal->logName, sizeof(pWal->logName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, fileId);
S
TD-1949  
Shengliang Guan 已提交
116

L
Liu Jicong 已提交
117 118
    if (remove(pWal->logName) < 0) {
      wError("vgId:%d, wal:%p file:%s, failed to remove since %s", pWal->vgId, pWal, pWal->logName, strerror(errno));
S
TD-1949  
Shengliang Guan 已提交
119
    } else {
L
Liu Jicong 已提交
120
      wInfo("vgId:%d, wal:%p file:%s, it is removed", pWal->vgId, pWal, pWal->logName);
S
TD-1949  
Shengliang Guan 已提交
121 122
    }
  }
S
TD-2087  
Shengliang Guan 已提交
123
  pthread_mutex_unlock(&pWal->mutex);
S
TD-1949  
Shengliang Guan 已提交
124
}
L
Liu Jicong 已提交
125
#endif
126

L
Liu Jicong 已提交
127
int64_t walWrite(SWal *pWal, int64_t index, uint8_t msgType, void *body, int32_t bodyLen) {
L
Liu Jicong 已提交
128
  if (pWal == NULL) return -1;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
129

S
TD-1652  
Shengliang Guan 已提交
130
  // no wal
L
Liu Jicong 已提交
131
  if (!tfValid(pWal->curLogTfd)) return 0;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
132
  if (pWal->level == TAOS_WAL_NOLOG) return 0;
L
Liu Jicong 已提交
133
  if (index > pWal->lastVersion + 1) return -1;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
134

L
Liu Jicong 已提交
135 136
  pWal->head.version = index;
  int32_t code = 0;
L
Liu Jicong 已提交
137

L
Liu Jicong 已提交
138 139 140
  pWal->head.signature = WAL_SIGNATURE;
  pWal->head.len = bodyLen;
  pWal->head.msgType = msgType;
141

L
Liu Jicong 已提交
142 143
  pWal->head.cksumHead = taosCalcChecksum(0, (const uint8_t*)&pWal->head, sizeof(SWalHead)- sizeof(uint32_t)*2);
  pWal->head.cksumBody = taosCalcChecksum(0, (const uint8_t*)&body, bodyLen);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
144

145 146
  pthread_mutex_lock(&pWal->mutex);

L
Liu Jicong 已提交
147 148
  if (tfWrite(pWal->curLogTfd, &pWal->head, sizeof(SWalHead)) != sizeof(SWalHead)) {
    //ftruncate
S
TD-1846  
Shengliang Guan 已提交
149
    code = TAOS_SYSTEM_ERROR(errno);
L
Liu Jicong 已提交
150
    wError("vgId:%d, file:%"PRId64".log, failed to write since %s", pWal->vgId, pWal->curFileFirstVersion, strerror(errno));
J
Jeff Tao 已提交
151
  }
S
TD-1846  
Shengliang Guan 已提交
152

L
Liu Jicong 已提交
153 154 155 156 157 158
  if (tfWrite(pWal->curLogTfd, &body, bodyLen) != bodyLen) {
    //ftruncate
    code = TAOS_SYSTEM_ERROR(errno);
    wError("vgId:%d, file:%"PRId64".log, failed to write since %s", pWal->vgId, pWal->curFileFirstVersion, strerror(errno));
  }
  //TODO:write idx
159

L
Liu Jicong 已提交
160
  pthread_mutex_unlock(&pWal->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
161

S
TD-1846  
Shengliang Guan 已提交
162
  return code;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
163 164
}

L
Liu Jicong 已提交
165
void walFsync(SWal *pWal, bool forceFsync) {
L
Liu Jicong 已提交
166
  if (pWal == NULL || !tfValid(pWal->curLogTfd)) return;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
167

S
TD-1948  
Shengliang Guan 已提交
168
  if (forceFsync || (pWal->level == TAOS_WAL_FSYNC && pWal->fsyncPeriod == 0)) {
L
Liu Jicong 已提交
169 170 171
    wTrace("vgId:%d, fileId:%"PRId64".log, do fsync", pWal->vgId, pWal->curFileFirstVersion);
    if (tfFsync(pWal->curLogTfd) < 0) {
      wError("vgId:%d, file:%"PRId64".log, fsync failed since %s", pWal->vgId, pWal->curFileFirstVersion, strerror(errno));
172 173
    }
  }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
174 175
}

L
Liu Jicong 已提交
176
#if 0
S
TD-1918  
Shengliang Guan 已提交
177
int32_t walRestore(void *handle, void *pVnode, FWalWrite writeFp) {
S
TD-1846  
Shengliang Guan 已提交
178
  if (handle == NULL) return -1;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
179

S
TD-1846  
Shengliang Guan 已提交
180 181
  SWal *  pWal = handle;
  int32_t count = 0;
S
TD-1846  
Shengliang Guan 已提交
182 183
  int32_t code = 0;
  int64_t fileId = -1;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
184

S
TD-1846  
Shengliang Guan 已提交
185
  while ((code = walGetNextFile(pWal, &fileId)) >= 0) {
L
Liu Jicong 已提交
186
    /*if (fileId == pWal->curFileId) continue;*/
J
Jeff Tao 已提交
187

S
TD-1846  
Shengliang Guan 已提交
188
    char walName[WAL_FILE_LEN];
L
Liu Jicong 已提交
189
    snprintf(walName, sizeof(pWal->logName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, fileId);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
190

S
TD-2381  
Shengliang Guan 已提交
191
    wInfo("vgId:%d, file:%s, will be restored", pWal->vgId, walName);
192
    code = walRestoreWalFile(pWal, pVnode, writeFp, walName, fileId);
S
TD-1846  
Shengliang Guan 已提交
193
    if (code != TSDB_CODE_SUCCESS) {
S
Shengliang Guan 已提交
194
      wError("vgId:%d, file:%s, failed to restore since %s", pWal->vgId, walName, tstrerror(code));
S
TD-1846  
Shengliang Guan 已提交
195 196
      continue;
    }
S
TD-1846  
Shengliang Guan 已提交
197

L
Liu Jicong 已提交
198
    wInfo("vgId:%d, file:%s, restore success, wver:%" PRIu64, pWal->vgId, walName, pWal->curVersion);
S
TD-1846  
Shengliang Guan 已提交
199 200

    count++;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
201 202
  }

L
Liu Jicong 已提交
203
  /*if (pWal->keep != TAOS_WAL_KEEP) return TSDB_CODE_SUCCESS;*/
S
TD-1846  
Shengliang Guan 已提交
204 205

  if (count == 0) {
S
TD-1894  
Shengliang Guan 已提交
206
    wDebug("vgId:%d, wal file not exist, renew it", pWal->vgId);
S
TD-1846  
Shengliang Guan 已提交
207 208 209
    return walRenew(pWal);
  } else {
    // open the existing WAL file in append mode
L
Liu Jicong 已提交
210 211 212 213 214
    /*pWal->curFileId = 0;*/
    snprintf(pWal->logName, sizeof(pWal->logName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->curFileId);
    pWal->logTfd = tfOpenCreateWriteAppend(pWal->logName);
    if (!tfValid(pWal->logTfd)) {
      wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->logName, strerror(errno));
S
TD-1846  
Shengliang Guan 已提交
215
      return TAOS_SYSTEM_ERROR(errno);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
216
    }
L
Liu Jicong 已提交
217
    wDebug("vgId:%d, file:%s, it is created and open while restore", pWal->vgId, pWal->logName);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
218 219
  }

S
TD-1846  
Shengliang Guan 已提交
220
  return TSDB_CODE_SUCCESS;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
221 222
}

S
TD-1846  
Shengliang Guan 已提交
223 224 225
int32_t walGetWalFile(void *handle, char *fileName, int64_t *fileId) {
  if (handle == NULL) return -1;
  SWal *pWal = handle;
226

S
TD-1846  
Shengliang Guan 已提交
227 228
  if (*fileId == 0) *fileId = -1;

229
  pthread_mutex_lock(&(pWal->mutex));
S
TD-1846  
Shengliang Guan 已提交
230

S
TD-1846  
Shengliang Guan 已提交
231 232 233
  int32_t code = walGetNextFile(pWal, fileId);
  if (code >= 0) {
    sprintf(fileName, "wal/%s%" PRId64, WAL_PREFIX, *fileId);
L
Liu Jicong 已提交
234
    /*code = (*fileId == pWal->curFileId) ? 0 : 1;*/
235
  }
S
TD-1846  
Shengliang Guan 已提交
236

L
Liu Jicong 已提交
237
  wDebug("vgId:%d, get wal file, code:%d curId:%" PRId64 " outId:%" PRId64, pWal->vgId, code, pWal->curFileId, *fileId);
238 239 240
  pthread_mutex_unlock(&(pWal->mutex));

  return code;
S
TD-1652  
Shengliang Guan 已提交
241
}
L
Liu Jicong 已提交
242
#endif
243

S
TD-1895  
Shengliang Guan 已提交
244 245 246
static void walFtruncate(SWal *pWal, int64_t tfd, int64_t offset) {
  tfFtruncate(tfd, offset);
  tfFsync(tfd);
S
TD-1891  
Shengliang Guan 已提交
247 248
}

L
Liu Jicong 已提交
249
#if 0
S
TD-1895  
Shengliang Guan 已提交
250
static int32_t walSkipCorruptedRecord(SWal *pWal, SWalHead *pHead, int64_t tfd, int64_t *offset) {
S
TD-1891  
Shengliang Guan 已提交
251 252 253 254
  int64_t pos = *offset;
  while (1) {
    pos++;

S
TD-1895  
Shengliang Guan 已提交
255
    if (tfLseek(tfd, pos, SEEK_SET) < 0) {
S
TD-1891  
Shengliang Guan 已提交
256 257 258 259
      wError("vgId:%d, failed to seek from corrupted wal file since %s", pWal->vgId, strerror(errno));
      return TSDB_CODE_WAL_FILE_CORRUPTED;
    }

S
TD-1895  
Shengliang Guan 已提交
260
    if (tfRead(tfd, pHead, sizeof(SWalHead)) <= 0) {
S
TD-1891  
Shengliang Guan 已提交
261 262 263 264 265 266 267 268
      wError("vgId:%d, read to end of corrupted wal file, offset:%" PRId64, pWal->vgId, pos);
      return TSDB_CODE_WAL_FILE_CORRUPTED;
    }

    if (pHead->signature != WAL_SIGNATURE) {
      continue;
    }

C
Cary Xu 已提交
269
    if (pHead->sver >= 1) {
270 271 272 273 274 275 276 277 278 279 280
      if (tfRead(tfd, pHead->cont, pHead->len) < pHead->len) {
	wError("vgId:%d, read to end of corrupted wal file, offset:%" PRId64, pWal->vgId, pos);
	return TSDB_CODE_WAL_FILE_CORRUPTED;
      }

      if (walValidateChecksum(pHead)) {
	wInfo("vgId:%d, wal whole cksum check passed, offset:%" PRId64, pWal->vgId, pos);
	*offset = pos;
	return TSDB_CODE_SUCCESS;
      }
    }
S
TD-1891  
Shengliang Guan 已提交
281 282 283 284
  }

  return TSDB_CODE_WAL_FILE_CORRUPTED;
}
285

S
TD-1882  
Shengliang Guan 已提交
286
static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, char *name, int64_t fileId) {
S
TD-1846  
Shengliang Guan 已提交
287
  int32_t size = WAL_MAX_SIZE;
L
Liu Jicong 已提交
288
  void *  buffer = malloc(size);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
289
  if (buffer == NULL) {
S
TD-1846  
Shengliang Guan 已提交
290
    wError("vgId:%d, file:%s, failed to open for restore since %s", pWal->vgId, name, strerror(errno));
S
TD-1846  
Shengliang Guan 已提交
291
    return TAOS_SYSTEM_ERROR(errno);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
292
  }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
293

294
  int64_t tfd = tfOpenReadWrite(name);
S
TD-1895  
Shengliang Guan 已提交
295
  if (!tfValid(tfd)) {
S
TD-1846  
Shengliang Guan 已提交
296
    wError("vgId:%d, file:%s, failed to open for restore since %s", pWal->vgId, name, strerror(errno));
S
TD-1846  
Shengliang Guan 已提交
297 298
    tfree(buffer);
    return TAOS_SYSTEM_ERROR(errno);
S
Shengliang Guan 已提交
299 300
  } else {
    wDebug("vgId:%d, file:%s, open for restore", pWal->vgId, name);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
301 302
  }

S
TD-1846  
Shengliang Guan 已提交
303
  int32_t   code = TSDB_CODE_SUCCESS;
S
Shengliang Guan 已提交
304
  int64_t   offset = 0;
S
TD-1846  
Shengliang Guan 已提交
305 306
  SWalHead *pHead = buffer;

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
307
  while (1) {
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
    int32_t ret = (int32_t)tfRead(tfd, pHead, sizeof(SWalHead));
    if (ret == 0) break;

    if (ret < 0) {
      wError("vgId:%d, file:%s, failed to read wal head since %s", pWal->vgId, name, strerror(errno));
      code = TAOS_SYSTEM_ERROR(errno);
      break;
    }

    if (ret < sizeof(SWalHead)) {
      wError("vgId:%d, file:%s, failed to read wal head, ret is %d", pWal->vgId, name, ret);
      walFtruncate(pWal, tfd, offset);
      break;
    }

323
    if ((pHead->sver == 0 && !walValidateChecksum(pHead)) || pHead->sver < 0 || pHead->sver > 2) {
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
      wError("vgId:%d, file:%s, wal head cksum is messed up, hver:%" PRIu64 " len:%d offset:%" PRId64, pWal->vgId, name,
             pHead->version, pHead->len, offset);
      code = walSkipCorruptedRecord(pWal, pHead, tfd, &offset);
      if (code != TSDB_CODE_SUCCESS) {
        walFtruncate(pWal, tfd, offset);
        break;
      }
    }

    if (pHead->len < 0 || pHead->len > size - sizeof(SWalHead)) {
      wError("vgId:%d, file:%s, wal head len out of range, hver:%" PRIu64 " len:%d offset:%" PRId64, pWal->vgId, name,
             pHead->version, pHead->len, offset);
      code = walSkipCorruptedRecord(pWal, pHead, tfd, &offset);
      if (code != TSDB_CODE_SUCCESS) {
        walFtruncate(pWal, tfd, offset);
        break;
      }
    }

    ret = (int32_t)tfRead(tfd, pHead->cont, pHead->len);
    if (ret < 0) {
      wError("vgId:%d, file:%s, failed to read wal body since %s", pWal->vgId, name, strerror(errno));
      code = TAOS_SYSTEM_ERROR(errno);
      break;
    }

    if (ret < pHead->len) {
      wError("vgId:%d, file:%s, failed to read wal body, ret:%d len:%d", pWal->vgId, name, ret, pHead->len);
      offset += sizeof(SWalHead);
      continue;
    }

C
Cary Xu 已提交
356
    if ((pHead->sver >= 1) && !walValidateChecksum(pHead)) {
357 358 359 360 361 362 363 364 365
      wError("vgId:%d, file:%s, wal whole cksum is messed up, hver:%" PRIu64 " len:%d offset:%" PRId64, pWal->vgId, name,
             pHead->version, pHead->len, offset);
      code = walSkipCorruptedRecord(pWal, pHead, tfd, &offset);
      if (code != TSDB_CODE_SUCCESS) {
        walFtruncate(pWal, tfd, offset);
        break;
      }
    }

H
Hongze Cheng 已提交
366 367
    offset = offset + sizeof(SWalHead) + pHead->len;

S
TD-4176  
Shengliang Guan 已提交
368
    wTrace("vgId:%d, restore wal, fileId:%" PRId64 " hver:%" PRIu64 " wver:%" PRIu64 " len:%d offset:%" PRId64,
L
Liu Jicong 已提交
369
           pWal->vgId, fileId, pHead->version, pWal->curVersion, pHead->len, offset);
S
TD-1846  
Shengliang Guan 已提交
370

L
Liu Jicong 已提交
371
    pWal->curVersion = pHead->version;
372

373
    // wInfo("writeFp: %ld", offset);
L
Liu Jicong 已提交
374
    (*writeFp)(pVnode, pHead);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
375 376
  }

S
TD-1895  
Shengliang Guan 已提交
377
  tfClose(tfd);
S
TD-1846  
Shengliang Guan 已提交
378
  tfree(buffer);
J
Jeff Tao 已提交
379

S
Shengliang Guan 已提交
380
  wDebug("vgId:%d, file:%s, it is closed after restore", pWal->vgId, name);
S
TD-1846  
Shengliang Guan 已提交
381
  return code;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
382
}
L
Liu Jicong 已提交
383
#endif