private String versionPath(Version ver) { return versionPath(ver.value()) ; } private String versionPath(long ver) { return Zk.zkPath(versionsPath, String.format("%08d", ver)); }
@Override public Id versionToId(Version ver) { // Cache? if ( ! Version.isValid(ver) ) return null; String p = versionPath(ver); byte[] b = Zk.zkFetch(client, versionPath(ver)); if ( b == null ) return null; Id id = Id.fromBytes(b); return id; }
private void save(long version, Id patch, Id prev) { newState(version, patch, prev); JsonObject x = stateToJson(version, patch, prev); byte[] bytes = JSONX.asBytes(x); if ( patch != null ) { // [META] // Record the basic header - (version, id, prev) - for validation. if ( keepHeaderInfo ) Zk.zkCreateSet(client, headerPath(patch), bytes); // Write version->id mapping. Zk.zkCreateSet(client, versionPath(version), patch.asBytes()); } Zk.zkSet(client, statePath, bytes); }