Merge pull request #29639 from taosdata/feat/3.0/TS-5795
Enh(tsdb):print fid while data file corrupted.
This commit is contained in:
commit
e1cd2735a6
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tsdbDataFileRW.h"
|
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
|
#include "tsdbDataFileRW.h"
|
||||||
|
|
||||||
// SDataFileReader =============================================
|
// SDataFileReader =============================================
|
||||||
struct 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 tsdbDataFileReadBlockData(SDataFileReader *reader, const SBrinRecord *record, SBlockData *bData) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
int32_t fid = reader->config->files[TSDB_FTYPE_DATA].file.fid;
|
||||||
|
|
||||||
SBuffer *buffer = reader->buffers + 0;
|
SBuffer *buffer = reader->buffers + 0;
|
||||||
SBuffer *assist = reader->buffers + 1;
|
SBuffer *assist = reader->buffers + 1;
|
||||||
|
@ -321,8 +322,8 @@ int32_t tsdbDataFileReadBlockData(SDataFileReader *reader, const SBrinRecord *re
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, __FILE__, lino,
|
tsdbError("vgId:%d %s fid %d failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, fid,
|
||||||
tstrerror(code));
|
__FILE__, lino, tstrerror(code));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -331,6 +332,7 @@ int32_t tsdbDataFileReadBlockDataByColumn(SDataFileReader *reader, const SBrinRe
|
||||||
STSchema *pTSchema, int16_t cids[], int32_t ncid) {
|
STSchema *pTSchema, int16_t cids[], int32_t ncid) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
int32_t fid = reader->config->files[TSDB_FTYPE_DATA].file.fid;
|
||||||
|
|
||||||
SDiskDataHdr hdr;
|
SDiskDataHdr hdr;
|
||||||
SBuffer *buffer0 = reader->buffers + 0;
|
SBuffer *buffer0 = reader->buffers + 0;
|
||||||
|
@ -505,8 +507,8 @@ int32_t tsdbDataFileReadBlockDataByColumn(SDataFileReader *reader, const SBrinRe
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, __FILE__, lino,
|
tsdbError("vgId:%d %s fid:%d failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, fid,
|
||||||
tstrerror(code));
|
__FILE__, lino, tstrerror(code));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue