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 ) ; }
Persists the given metadata into ZooKeeper .