refact code
This commit is contained in:
parent
1132a7f719
commit
7d23c83091
|
@ -37,7 +37,7 @@ typedef struct {
|
||||||
int32_t iBlockL;
|
int32_t iBlockL;
|
||||||
SBlockData bData;
|
SBlockData bData;
|
||||||
int32_t iRow;
|
int32_t iRow;
|
||||||
}; // last file data iter
|
}; // sst file data iter
|
||||||
};
|
};
|
||||||
} SDataIter;
|
} SDataIter;
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ _err:
|
||||||
// taosRemoveFile(fname);
|
// taosRemoveFile(fname);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// // last
|
// // sst
|
||||||
// if (isSameDisk && pFrom->pLastF->commitID == pTo->pLastF->commitID) {
|
// if (isSameDisk && pFrom->pLastF->commitID == pTo->pLastF->commitID) {
|
||||||
// if (pFrom->pLastF->size > pTo->pLastF->size) {
|
// if (pFrom->pLastF->size > pTo->pLastF->size) {
|
||||||
// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_LAST_FILE);
|
// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_LAST_FILE);
|
||||||
|
@ -140,7 +140,7 @@ _err:
|
||||||
// tsdbDataFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pDataF, fname);
|
// tsdbDataFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pDataF, fname);
|
||||||
// taosRemoveFile(fname);
|
// taosRemoveFile(fname);
|
||||||
|
|
||||||
// // last
|
// // sst
|
||||||
// tsdbLastFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pLastF, fname);
|
// tsdbLastFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pLastF, fname);
|
||||||
// taosRemoveFile(fname);
|
// taosRemoveFile(fname);
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// last ===========
|
// sst ===========
|
||||||
tsdbSstFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSstF[0], fname);
|
tsdbSstFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSstF[0], fname);
|
||||||
if (taosStatFile(fname, &size, NULL)) {
|
if (taosStatFile(fname, &size, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
@ -508,13 +508,15 @@ int32_t tsdbFSClose(STsdb *pTsdb) {
|
||||||
ASSERT(pSet->pDataF->nRef == 1);
|
ASSERT(pSet->pDataF->nRef == 1);
|
||||||
taosMemoryFree(pSet->pDataF);
|
taosMemoryFree(pSet->pDataF);
|
||||||
|
|
||||||
// last
|
|
||||||
ASSERT(pSet->aSstF[0]->nRef == 1);
|
|
||||||
taosMemoryFree(pSet->aSstF[0]);
|
|
||||||
|
|
||||||
// sma
|
// sma
|
||||||
ASSERT(pSet->pSmaF->nRef == 1);
|
ASSERT(pSet->pSmaF->nRef == 1);
|
||||||
taosMemoryFree(pSet->pSmaF);
|
taosMemoryFree(pSet->pSmaF);
|
||||||
|
|
||||||
|
// sst
|
||||||
|
for (int32_t iSst = 0; iSst < pSet->nSstF; iSst++) {
|
||||||
|
ASSERT(pSet->aSstF[iSst]->nRef == 1);
|
||||||
|
taosMemoryFree(pSet->aSstF[iSst]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(pTsdb->fs.aDFileSet);
|
taosArrayDestroy(pTsdb->fs.aDFileSet);
|
||||||
|
@ -570,7 +572,7 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
|
||||||
}
|
}
|
||||||
*fSet.pSmaF = *pSet->pSmaF;
|
*fSet.pSmaF = *pSet->pSmaF;
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
for (fSet.nSstF = 0; fSet.nSstF < pSet->nSstF; fSet.nSstF++) {
|
for (fSet.nSstF = 0; fSet.nSstF < pSet->nSstF; fSet.nSstF++) {
|
||||||
fSet.aSstF[fSet.nSstF] = (SSstFile *)taosMemoryMalloc(sizeof(SSstFile));
|
fSet.aSstF[fSet.nSstF] = (SSstFile *)taosMemoryMalloc(sizeof(SSstFile));
|
||||||
if (fSet.aSstF[fSet.nSstF] == NULL) {
|
if (fSet.aSstF[fSet.nSstF] == NULL) {
|
||||||
|
@ -630,7 +632,7 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
|
||||||
*pDFileSet->pHeadF = *pSet->pHeadF;
|
*pDFileSet->pHeadF = *pSet->pHeadF;
|
||||||
*pDFileSet->pDataF = *pSet->pDataF;
|
*pDFileSet->pDataF = *pSet->pDataF;
|
||||||
*pDFileSet->pSmaF = *pSet->pSmaF;
|
*pDFileSet->pSmaF = *pSet->pSmaF;
|
||||||
// last
|
// sst
|
||||||
if (pSet->nSstF > pDFileSet->nSstF) {
|
if (pSet->nSstF > pDFileSet->nSstF) {
|
||||||
ASSERT(pSet->nSstF == pDFileSet->nSstF + 1);
|
ASSERT(pSet->nSstF == pDFileSet->nSstF + 1);
|
||||||
|
|
||||||
|
@ -686,7 +688,7 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
|
||||||
}
|
}
|
||||||
*fSet.pSmaF = *pSet->pSmaF;
|
*fSet.pSmaF = *pSet->pSmaF;
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
fSet.aSstF[0] = (SSstFile *)taosMemoryMalloc(sizeof(SSstFile));
|
fSet.aSstF[0] = (SSstFile *)taosMemoryMalloc(sizeof(SSstFile));
|
||||||
if (fSet.aSstF[0] == NULL) {
|
if (fSet.aSstF[0] == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -860,7 +862,7 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
|
||||||
pSetOld->pSmaF->size = pSetNew->pSmaF->size;
|
pSetOld->pSmaF->size = pSetNew->pSmaF->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
if (sameDisk) {
|
if (sameDisk) {
|
||||||
if (pSetNew->nSstF > pSetOld->nSstF) {
|
if (pSetNew->nSstF > pSetOld->nSstF) {
|
||||||
ASSERT(pSetNew->nSstF = pSetOld->nSstF + 1);
|
ASSERT(pSetNew->nSstF = pSetOld->nSstF + 1);
|
||||||
|
@ -1005,7 +1007,7 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
|
||||||
*fSet.pSmaF = *pSetNew->pSmaF;
|
*fSet.pSmaF = *pSetNew->pSmaF;
|
||||||
fSet.pSmaF->nRef = 1;
|
fSet.pSmaF->nRef = 1;
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
ASSERT(pSetNew->nSstF == 1);
|
ASSERT(pSetNew->nSstF == 1);
|
||||||
fSet.aSstF[0] = (SSstFile *)taosMemoryMalloc(sizeof(SSstFile));
|
fSet.aSstF[0] = (SSstFile *)taosMemoryMalloc(sizeof(SSstFile));
|
||||||
if (fSet.aSstF[0] == NULL) {
|
if (fSet.aSstF[0] == NULL) {
|
||||||
|
@ -1120,7 +1122,7 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
|
||||||
taosMemoryFree(pSet->pSmaF);
|
taosMemoryFree(pSet->pSmaF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
for (int32_t iLast = 0; iLast < pSet->nSstF; iLast++) {
|
for (int32_t iLast = 0; iLast < pSet->nSstF; iLast++) {
|
||||||
nRef = atomic_sub_fetch_32(&pSet->aSstF[iLast]->nRef, 1);
|
nRef = atomic_sub_fetch_32(&pSet->aSstF[iLast]->nRef, 1);
|
||||||
ASSERT(nRef >= 0);
|
ASSERT(nRef >= 0);
|
||||||
|
|
|
@ -194,7 +194,7 @@ int32_t tPutDFileSet(uint8_t *p, SDFileSet *pSet) {
|
||||||
n += tPutDataFile(p ? p + n : p, pSet->pDataF);
|
n += tPutDataFile(p ? p + n : p, pSet->pDataF);
|
||||||
n += tPutSmaFile(p ? p + n : p, pSet->pSmaF);
|
n += tPutSmaFile(p ? p + n : p, pSet->pSmaF);
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
n += tPutU8(p ? p + n : p, pSet->nSstF);
|
n += tPutU8(p ? p + n : p, pSet->nSstF);
|
||||||
for (int32_t iLast = 0; iLast < pSet->nSstF; iLast++) {
|
for (int32_t iLast = 0; iLast < pSet->nSstF; iLast++) {
|
||||||
n += tPutSstFile(p ? p + n : p, pSet->aSstF[iLast]);
|
n += tPutSstFile(p ? p + n : p, pSet->aSstF[iLast]);
|
||||||
|
@ -234,7 +234,7 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) {
|
||||||
pSet->pSmaF->nRef = 1;
|
pSet->pSmaF->nRef = 1;
|
||||||
n += tGetSmaFile(p + n, pSet->pSmaF);
|
n += tGetSmaFile(p + n, pSet->pSmaF);
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
n += tGetU8(p + n, &pSet->nSstF);
|
n += tGetU8(p + n, &pSet->nSstF);
|
||||||
for (int32_t iLast = 0; iLast < pSet->nSstF; iLast++) {
|
for (int32_t iLast = 0; iLast < pSet->nSstF; iLast++) {
|
||||||
pSet->aSstF[iLast] = (SSstFile *)taosMemoryCalloc(1, sizeof(SSstFile));
|
pSet->aSstF[iLast] = (SSstFile *)taosMemoryCalloc(1, sizeof(SSstFile));
|
||||||
|
|
|
@ -433,7 +433,7 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
for (int32_t iLast = 0; iLast < pSet->nSstF; iLast++) {
|
for (int32_t iLast = 0; iLast < pSet->nSstF; iLast++) {
|
||||||
tsdbSstFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSstF[iLast], fname);
|
tsdbSstFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSstF[iLast], fname);
|
||||||
pReader->aLastFD[iLast] = taosOpenFile(fname, TD_FILE_READ);
|
pReader->aLastFD[iLast] = taosOpenFile(fname, TD_FILE_READ);
|
||||||
|
@ -474,7 +474,7 @@ int32_t tsdbDataFReaderClose(SDataFReader **ppReader) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
for (int32_t iLast = 0; iLast < (*ppReader)->pSet->nSstF; iLast++) {
|
for (int32_t iLast = 0; iLast < (*ppReader)->pSet->nSstF; iLast++) {
|
||||||
if (taosCloseFile(&(*ppReader)->aLastFD[iLast]) < 0) {
|
if (taosCloseFile(&(*ppReader)->aLastFD[iLast]) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
@ -1036,7 +1036,7 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
|
||||||
ASSERT(n == pWriter->fSma.size);
|
ASSERT(n == pWriter->fSma.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
ASSERT(pWriter->fSst[pSet->nSstF - 1].size == 0);
|
ASSERT(pWriter->fSst[pSet->nSstF - 1].size == 0);
|
||||||
flag = TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC;
|
flag = TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC;
|
||||||
tsdbSstFileName(pTsdb, pWriter->wSet.diskId, pWriter->wSet.fid, &pWriter->fSst[pSet->nSstF - 1], fname);
|
tsdbSstFileName(pTsdb, pWriter->wSet.diskId, pWriter->wSet.fid, &pWriter->fSst[pSet->nSstF - 1], fname);
|
||||||
|
@ -1179,7 +1179,7 @@ int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// last ==============
|
// sst ==============
|
||||||
memset(hdr, 0, TSDB_FHDR_SIZE);
|
memset(hdr, 0, TSDB_FHDR_SIZE);
|
||||||
tPutSstFile(hdr, &pWriter->fSst[pWriter->wSet.nSstF - 1]);
|
tPutSstFile(hdr, &pWriter->fSst[pWriter->wSet.nSstF - 1]);
|
||||||
taosCalcChecksumAppend(0, hdr, TSDB_FHDR_SIZE);
|
taosCalcChecksumAppend(0, hdr, TSDB_FHDR_SIZE);
|
||||||
|
@ -1554,7 +1554,7 @@ int32_t tsdbDFileSetCopy(STsdb *pTsdb, SDFileSet *pSetFrom, SDFileSet *pSetTo) {
|
||||||
taosCloseFile(&pOutFD);
|
taosCloseFile(&pOutFD);
|
||||||
taosCloseFile(&PInFD);
|
taosCloseFile(&PInFD);
|
||||||
|
|
||||||
// last
|
// sst
|
||||||
tsdbSstFileName(pTsdb, pSetFrom->diskId, pSetFrom->fid, pSetFrom->aSstF[0], fNameFrom);
|
tsdbSstFileName(pTsdb, pSetFrom->diskId, pSetFrom->fid, pSetFrom->aSstF[0], fNameFrom);
|
||||||
tsdbSstFileName(pTsdb, pSetTo->diskId, pSetTo->fid, pSetTo->aSstF[0], fNameTo);
|
tsdbSstFileName(pTsdb, pSetTo->diskId, pSetTo->fid, pSetTo->aSstF[0], fNameTo);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue