{"record":{"id":"a672057b65114cb0","repo":"alibaba/canal","slug":"count-is-not-supportted-in-tablestore","errorCode":null,"errorMessage":"count is not supportted in tablestore","messagePattern":"count is not supportted in tablestore","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"client-adapter/tablestore/src/main/java/com/alibaba/otter/canal/client/adapter/tablestore/TablestoreAdapter.java","lineNumber":243,"sourceCode":"        config.setAllowDuplicatedRowInBatchRequest(true);\n        config.setConcurrency(8);\n        config.setWriteMode(WriteMode.PARALLEL);\n\n        TableStoreWriter writer = new DefaultTableStoreWriter(\n                properties.get(PropertyConstants.TABLESTORE_ENDPOINT),\n                credentials,\n                properties.get(PropertyConstants.TABLESTORE_INSTANCENAME),\n                mappingConfig.getDbMapping().getTargetTable(),\n                config,\n                null\n        );\n        return writer;\n    }\n\n\n    @Override\n    public Map<String, Object> count(String task) {\n        throw new RuntimeException(\"count is not supportted in tablestore\");\n    }\n\n\n    @Override\n    public String getDestination(String task) {\n        MappingConfig config = tablestoreMapping.get(task);\n        if (config != null) {\n            return config.getDestination();\n        }\n        return null;\n    }\n\n    @Override\n    public void destroy() {\n        if (tablestoreSyncService != null) {\n            tablestoreSyncService.close();\n        }\n","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/client-adapter/tablestore/src/main/java/com/alibaba/otter/canal/client/adapter/tablestore/TablestoreAdapter.java#L225-L261","documentation":"The TablestoreAdapter unconditionally throws this from the count() method override, because Alibaba Tablestore (OTS) does not provide a native count/aggregate API. The method exists to satisfy the CanalAdapter interface contract but is intentionally unimplemented. Any caller that invokes count() on a tablestore adapter will hit this immediately.","triggerScenarios":"Calling TablestoreAdapter.count(task) from any code path — typically from a monitoring endpoint, admin tool, or test that attempts to retrieve row counts from the target tablestore table.","commonSituations":"A monitoring script or canal-admin dashboard calls count() on all adapters including tablestore; automated tests iterate all adapter types and call count(); custom code that assumes all adapters support counting.","solutions":["Do not call count() on a TablestoreAdapter — it is unsupported by design.","If row counting is needed, query the OTS API separately using a RangeIterator or maintain a separate counter table.","Guard the caller to skip tablestore adapters when invoking count(), checking the adapter type or catching this exception."],"exampleFix":"// before: blindly calls count on all adapters\nfor (CanalAdapter adapter : adapters) {\n    Map<String, Object> counts = adapter.count(task);\n}\n\n// after: skip unsupported adapters\nfor (CanalAdapter adapter : adapters) {\n    if (!(adapter instanceof TablestoreAdapter)) {\n        Map<String, Object> counts = adapter.count(task);\n    }\n}","handlingStrategy":"type-guard","validationCode":"null","typeGuard":"// Type guard: check adapter type before calling count\npublic static boolean supportsCount(CanalAdapter adapter) {\n    return !(adapter instanceof TablestoreAdapter);\n}\n\n// Usage:\nif (supportsCount(adapter)) {\n    Map<String, Object> counts = adapter.count(task);\n}","tryCatchPattern":"try {\n    Map<String, Object> counts = adapter.count(task);\n} catch (RuntimeException e) {\n    if (\"count is not supportted in tablestore\".equals(e.getMessage())) {\n        // expected for tablestore; skip\n        logger.debug(\"count() not supported by this adapter\");\n    } else {\n        throw e;\n    }\n}","preventionTips":["Do not call count() on TablestoreAdapter — it is unsupported by design.","When iterating heterogeneous adapters, guard count() calls with an instanceof check.","If counts are needed for monitoring, use OTS API directly or a separate counter mechanism."],"tags":["tablestore-adapter","unsupported-operation","api-limitation"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}