{"record":{"id":"3ac30b08bf78f8c7","repo":"iflytek/astron-agent","slug":"8522-database-table-copy-failed","errorCode":"8522","errorMessage":"database.table.copy.failed","messagePattern":"database\\.table\\.copy\\.failed","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java","lineNumber":998,"sourceCode":"            copyTable.setCreateTime(new Date());\n            copyTable.setUpdateTime(new Date());\n            dbTableMapper.insert(copyTable);\n\n            List<DbTableField> dbTableFields = dbTableFieldMapper.selectList(new QueryWrapper<DbTableField>().lambda()\n                    .eq(DbTableField::getTbId, tbId));\n            List<DbTableField> copyTableFields = new ArrayList<>();\n            for (DbTableField dbTableField : dbTableFields) {\n                DbTableField copyTableField = new DbTableField();\n                BeanUtils.copyProperties(dbTableField, copyTableField);\n                copyTableField.setTbId(copyTable.getId());\n                copyTableField.setCreateTime(new Date());\n                copyTableField.setUpdateTime(new Date());\n                copyTableFields.add(copyTableField);\n            }\n            dbTableFieldMapper.insertBatch(copyTableFields);\n        } catch (Exception ex) {\n            log.error(\"copy table failed, tbId={}\", tbId, ex);\n            throw new BusinessException(ResponseEnum.DATABASE_TABLE_COPY_FAILED);\n        }\n    }\n\n    public void exportTableData(DatabaseExportDto dto, HttpServletResponse response) {\n        dataPermissionCheckTool.checkTbBelong(dto.getTbId());\n        try {\n            DbTable dbTable = dbTableMapper.selectById(dto.getTbId());\n            DbInfo dbInfo = dbInfoMapper.selectById(dbTable.getDbId());\n\n            String table = dialect.quoteIdent(dbTable.getName());\n            String dml = \"SELECT * FROM \" + table + \" LIMIT 1000 OFFSET 0\";\n\n            if (dto.getDataIds() != null && !dto.getDataIds().isEmpty()) {\n                if (dto.getDataIds().size() > MAX_EXPORT_IDS) {\n                    throw new BusinessException(ResponseEnum.DATABASE_TOO_MANY_EXPORT_IDS);\n                }\n                // All perform digital whitelist verification\n                List<Long> ids = dto.getDataIds()","sourceCodeStart":980,"sourceCodeEnd":1016,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L980-L1016","documentation":"Thrown by DatabaseService.copyTable when copying a table (its metadata row and field rows) fails. Code 8522, message 'database.table.copy.failed'. The method is @Transactional, so any exception here rolls back the partial copy; this error reports the wrapped cause.","triggerScenarios":"Calling copyTable(tbId) when the source table lookup fails, the insert of the copied DbTable row fails (duplicate generated name, DB down), or insertBatch of the copied fields fails (e.g. batch too large, constraint violation).","commonSituations":"Many rapid copies hitting a unique-name constraint; connection pool exhaustion mid-transaction; field batch exceeding DB packet limits.","solutions":["Check log 'copy table failed, tbId=...' for the root-cause stack trace.","If duplicate-name, retry — a new name is typically generated per attempt.","Verify DB health and connection pool capacity; large batches may need splitting.","Because the method is transactional, confirm no partial rows remain; re-run the copy after fixing the cause."],"exampleFix":"// before\ndbTableFieldMapper.insertBatch(copyTableFields); // one huge batch can exceed limits\n// after\nfor (List<DbTableField> chunk : Lists.partition(copyTableFields, 500)) {\n    dbTableFieldMapper.insertBatch(chunk);\n}","handlingStrategy":"try-catch","validationCode":"Long exists = dbTableMapper.selectCount(new LambdaQueryWrapper<DbTable>().eq(DbTable::getTbId, tbId));\nif (exists == 0) throw new IllegalStateException(\"source table missing: \" + tbId);","typeGuard":null,"tryCatchPattern":"try {\n    databaseService.copyTable(tbId);\n} catch (BusinessException ex) {\n    if (\"database.table.copy.failed\".equals(ex.getMessage())) {\n        log.error(\"copy failed and rolled back; check duplicate names / DB health\", ex);\n    }\n    throw ex;\n}","preventionTips":["Space out rapid copies to avoid unique-name collisions","Chunk large field batches on insert","Monitor DB connection pool before bulk operations"],"tags":["database","copy","transaction"],"backgroundTag":"database-write-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}