@Test public void id_fromNode() { Id id1 = Id.create(); assertEquals(36, id1.asPlainString().length()); Id id2 = Id.fromNode(id1.asNode()); assertEquals(id1, id2); }
public static Id fromStringOrNull(String str) { return ( str == null ) ? null : fromString(str); }
private String idToKey(Id id) { return prefix+id.asParam(); }
@Test public void id_fromString() { Id id1 = Id.create(); assertTrue(id1.asNode().isURI()); assertEquals(36, id1.asParam().length()); Id id2 = Id.fromString(id1.asParam()); assertEquals(id1, id2); }
Id id = Id.fromString(idStr); String path = zkPath(headersPath, idStr); JsonObject obj = Zk.zkFetchJson(client, path); if ( ! mostRecent.equals(current) ) { /*msg*/ } if ( mostRecentPrev.equals(previous) ) { /*msg*/ } } else { if ( versionsCalc.size() != 1 ) { /*msg*/ }
public RDFPatch get(Id id) { //return patchCache.getIfPresent(id.asNode()); return patchCache.get(id.asNode()); }
@Override final public Version append(RDFPatch patch) { // System.err.println(">>append"); // RDFPatchOps.write(System.err, patch); // System.err.println("<<append"); return patchLogLockRtn(()->{ Id thisId = Id.fromNode(patch.getId()); Id prevId = Id.fromNode(patch.getPrevious()); // Is it a reply of the last patch? if ( ! isEmpty() && getLatestId().equals(thisId) ) { if ( Objects.equals(prevId, logIndex.getPreviousId()) ) FmtLog.warn(LOG, "Patch id matches log head, but patch previous does not match log previous id"); return getLatestVersion(); } PatchValidation.validateNewPatch(this, thisId, prevId, PatchValidation::badPatchEx); patchStorage.store(thisId, patch); Version version = logIndex.nextVersion(); // This is the commit point. Indeside the log lock. logIndex.save(version, thisId, prevId); return version; }); }
/** Update the version of the local data store */ private void setLocalState(Version version, Node patchId) { setLocalState(version, (patchId == null) ? null : Id.fromNode(patchId)); }
private static void validate(PatchLog log, PatchHeader header, Id patchId, Id previousId, BadHandler action) { if ( previousId != null ) { if ( ! log.contains(previousId) ) action.bad("Patch previous not found: patch=%s, previous=%s", patchId, previousId); Node prevId = header.getPrevious() ; if ( ! previousId.asNode().equals(prevId) ) action.bad("Patch previous header not found: patch=%s, previous=%s", patchId, previousId); } else { if ( header.getPrevious() != null ) action.bad("Patch previous header not found: patch=%s, previous=%s", patchId, previousId); } if ( ! previousId.equals(log.getLatestId()) ) { // No empty log, previousId != null but does not match log head. // Validation should have caught this. badPatchEx("Patch not an update on the latest logged one: id=%s prev=%s (log=[%d, %s])", patchId, previousId, log.getLatestVersion(), log.getLatestId()); } }
private String headerPath(Id id) { return Zk.zkPath(headersPath, id.asPlainString()); }
/** Called after writing the patch to the {@link PatchLog}. */ protected void afterWrite(DataSource source, RDFPatch rdfPatch, Version version, long timeElapsed) { // FmtLog.info(LOG, "append: finish: Patch=%s[ver=%d] ds=%s", // str(rdfPatch.getId()), version, source); //FmtLog.info(LOG, "append (%.3fs): Patch=%s[%s] ds=%s", (timeElapsed / 1000.0), str(rdfPatch.getId()), version, source); FmtLog.info(LOG, "append : Patch=%s(>%s)[%s] ds=%s", str(rdfPatch.getId()), str(rdfPatch.getPrevious()), version, source); }
public boolean isNil() { return this.equals(nilId); }
@Test public void id_3() { Id id1 = Id.nullId(); UUID uuid = UUID.fromString(id1.asPlainString()); assertEquals(0L, uuid.getMostSignificantBits()); assertEquals(0L, uuid.getLeastSignificantBits()); }
@Override public String toString() { return String.format("[%s, %s, [%s,%s] <%s>]", getDataSourceId(), getDataSourceName(), verString(minVersion), verString(maxVersion), (latestPatch==null)?"":latestPatch.toString()); }
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); }