Merge pull request #29639 from taosdata/feat/3.0/TS-5795

Enh(tsdb):print fid while data file corrupted.
This commit is contained in:
Shengliang Guan 2025-02-05 09:41:28 +08:00 committed by GitHub
commit e1cd2735a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 5 deletions

View File

@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tsdbDataFileRW.h"
#include "meta.h"
#include "tsdbDataFileRW.h"
// SDataFileReader =============================================
struct SDataFileReader {
@ -299,6 +299,7 @@ extern int32_t tBlockDataDecompress(SBufferReader *br, SBlockData *blockData, SB
int32_t tsdbDataFileReadBlockData(SDataFileReader *reader, const SBrinRecord *record, SBlockData *bData) {
int32_t code = 0;
int32_t lino = 0;
int32_t fid = reader->config->files[TSDB_FTYPE_DATA].file.fid;
SBuffer *buffer = reader->buffers + 0;
SBuffer *assist = reader->buffers + 1;
@ -321,8 +322,8 @@ int32_t tsdbDataFileReadBlockData(SDataFileReader *reader, const SBrinRecord *re
_exit:
if (code) {
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, __FILE__, lino,
tstrerror(code));
tsdbError("vgId:%d %s fid %d failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, fid,
__FILE__, lino, tstrerror(code));
}
return code;
}
@ -331,6 +332,7 @@ int32_t tsdbDataFileReadBlockDataByColumn(SDataFileReader *reader, const SBrinRe
STSchema *pTSchema, int16_t cids[], int32_t ncid) {
int32_t code = 0;
int32_t lino = 0;
int32_t fid = reader->config->files[TSDB_FTYPE_DATA].file.fid;
SDiskDataHdr hdr;
SBuffer *buffer0 = reader->buffers + 0;
@ -505,8 +507,8 @@ int32_t tsdbDataFileReadBlockDataByColumn(SDataFileReader *reader, const SBrinRe
_exit:
if (code) {
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, __FILE__, lino,
tstrerror(code));
tsdbError("vgId:%d %s fid:%d failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, fid,
__FILE__, lino, tstrerror(code));
}
return code;
}

View File

@ -0,0 +1,46 @@
import json
import sys
import shutil
import time
import os
import argparse
def main():
parser = argparse.ArgumentParser(description='Repair TSDB data by removing specified fid.')
parser.add_argument('fid', type=int, help='The fid to be removed')
parser.add_argument('file_path', nargs='?', default='current.json', help='The path to the JSON file (default: current.json)')
args = parser.parse_args()
target_fid = args.fid
file_path = args.file_path
# Read file content
with open(file_path, 'r') as file:
data = json.load(file)
# Check if the fid exists
fid_exists = any(item.get('fid') == target_fid for item in data['fset'])
if not fid_exists:
print(f"Error: fid {target_fid} does not exist in the file.")
sys.exit(1)
# Generate backup file name
timestamp = time.strftime("%Y%m%d%H%M%S")
parent_directory = os.path.dirname(os.path.dirname(file_path))
backup_file_path = os.path.join(parent_directory, f"current.json.{timestamp}")
# Backup file
shutil.copy(file_path, backup_file_path)
print(f"Backup created: {backup_file_path}")
# Remove objects with the specified fid from the fset list
data['fset'] = [item for item in data['fset'] if item.get('fid') != target_fid]
# Write the updated content back to the file, preserving the original format
with open(file_path, 'w') as file:
json.dump(data, file, separators=(',', ':'), ensure_ascii=False)
print(f"Removed content with fid {target_fid}.")
if __name__ == '__main__':
main()