public long getFinishedInstanceCount() {
        int count = 0;
        List<InstanceProfile> instances = instanceStore.getInstances(taskId);
        for (int i = 0; i < instances.size(); i++) {
            if (instances.get(i).getState() == InstanceStateEnum.FINISHED) {
                count++;
            }
        }
        return count;
    }
add instance to memory, if there is a record refer to the instance id exist we need to destroy it first.
inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/instance/InstanceManager.java