code: private void persistMetadata(LogMetadata metadata, boolean create) throws DurableDataLogException {
          try {
              byte[] serializedMetadata = LogMetadata.SERIALIZER.serialize(metadata).getCopy();
              if (create) {
                  this.zkClient.create()
                               .creatingParentsIfNeeded()
                               .forPath(this.logNodePath, serializedMetadata);
                  // Set version to 0 as that will match the ZNode's version.
                  metadata.withUpdateVersion(0);
              } else {
                  this.zkClient.setData()
                               .withVersion(metadata.getUpdateVersion())
                               .forPath(this.logNodePath, serializedMetadata);
  
                  // Increment the version to keep up with the ZNode's value (after writing it to ZK).
                  metadata.withUpdateVersion(metadata.getUpdateVersion() + 1);
              }
          } catch (KeeperException.NodeExistsException | KeeperException.BadVersionException keeperEx) {
              // We were fenced out. Clean up and throw appropriate exception.
              throw new DataLogWriterNotPrimaryException(
                      String.format("Unable to acquire exclusive write lock for log (path = '%s%s').", this.zkClient.getNamespace(), this.logNodePath),
                      keeperEx);
          } catch (Exception generalEx) {
              // General exception. Clean up and rethrow appropriate exception.
              throw new DataLogInitializationException(
                      String.format("Unable to update ZNode for path '%s%s'.", this.zkClient.getNamespace(), this.logNodePath),
                      generalEx);
          }
  
          log.info("{} Metadata persisted ({}).", this.traceObjectId, metadata);
      }
docs: Persists the given metadata into ZooKeeper.
  
  @param metadata The LogMetadata to persist. At the end of this method, this metadata will have its Version updated
  to the one in ZooKeeper.
  @param create   Whether to create (true) or update (false) the data in ZooKeeper.
  @throws DataLogWriterNotPrimaryException If the metadata update failed (if we were asked to create and the node
  already exists or if we had to update and there was a version mismatch).
  @throws DurableDataLogException          If another kind of exception occurred.