public synchronized Stat setData(String path, byte[] data, int version) throws KeeperException,
            InterruptedException {
        RetryCounter retryCounter = retryCounterFactory.create();
        byte[] newData = data;
        while (true) {
            try {
                return zk.setData(path, newData, version);
            } catch (KeeperException e) {
                ensureConnectivity(e);

                switch (e.code()) {
                    case CONNECTIONLOSS:
                    case SESSIONEXPIRED:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "setData");
                        break;
                    case BADVERSION:
                        // try to verify whether the previous setData success or not
                        // try {
                        // Stat stat = new Stat();
                        // byte[] revData = zk.getData(path, false, stat);
                        // int idLength = Bytes.toInt(revData, ID_LENGTH_SIZE);
                        // int dataLength = revData.length - ID_LENGTH_SIZE -
                        // idLength;
                        // int dataOffset = ID_LENGTH_SIZE + idLength;
                        //
                        // if (Bytes.compareTo(revData, ID_LENGTH_SIZE, id.length,
                        // revData, dataOffset, dataLength) == 0) {
                        // // the bad version is caused by previous successful
                        // // setData
                        // return stat;
                        // }
                        // }
                        // catch (KeeperException keeperException) {
                        // // the ZK is not reliable at this moment. just throwing
                        // // exception
                        // throw keeperException;
                        // }

                        // throw other exceptions and verified bad version
                        // exceptions
                    default:
                        throw e;
                }
            }
            retryCounter.sleepUntilNextRetry();
            retryCounter.useRetry();
        }
    }
setData is NOT an idempotent operation. Retry may cause BadVersion Exception Adding an
identifier field into the data to check whether badversion is caused by the result of
previous correctly setData

@return Stat instance
inlong-tubemq/tubemq-server/src/main/java/org/apache/inlong/tubemq/server/common/zookeeper/RecoverableZooKeeper.java