public static String verString(Version version) { if ( version == null ) return "<null>"; if ( version.equals(Version.UNSET) ) return "--"; return Long.toString(version.value()); }
@Override public void save(Version version, Id patch, Id prev) { // Should always be called inside the patch lock. save(version.value(), patch, prev); }
@Override public RDFPatch fetch(Version version) { return fetch(fileStore, version.value()); }
private String versionPath(Version ver) { return versionPath(ver.value()) ; } private String versionPath(long ver) { return Zk.zkPath(versionsPath, String.format("%08d", ver)); }
/** Sync until some version */ private void syncToVersion(Version version) { //long remoteVer = getRemoteVersionLatestOrDefault(VERSION_UNSET); if ( ! Version.isValid(version) ) { FmtLog.debug(LOG, "Sync: Asked for no patches to sync"); return; } Version localVer = getLocalVersion(); // // -1 ==> no entries, uninitialized. // if ( DeltaConst.versionUninitialized(localVer) ) { // FmtLog.info(LOG, "Sync: No log entries"); // localVer = DeltaConst.VERSION_INIT; // setLocalState(localVer, (Node)null); // return; // } if ( localVer.value() > version.value() ) FmtLog.info(LOG, "[%s] Local version ahead of remote : [local=%d, remote=%d]", datasourceId, getLocalVersion(), getRemoteVersionCached()); if ( localVer.value() >= version.value() ) return; // bring up-to-date. FmtLog.info(LOG, "Sync: Versions [%s, %s]", localVer, version); playPatches(localVer.value()+1, version.value()) ; //FmtLog.info(LOG, "Now: Versions [%d, %d]", getLocalVersion(), remoteVer); }
private void validateLatest() { if ( CHECKING ) { synchronized(this) { long x = fileStore.getCurrentIndex(); if ( x == latestVersion.value() ) return ; // latestVersion = -1 (UNSET) and getCurrentIndex==0 (INIT) is OK if ( latestVersion == Version.UNSET && x == VERSION_INIT ) return ; FmtLog.error(LOG, "Out of sync: latestVersion=%s, fileStore=%s", latestVersion, x); } } }
@Override public Stream<RDFPatch> range(Id start, Id finish) { Version startVersion = idToVersion.get(start); Version finishVersion = idToVersion.get(finish); if ( startVersion == null ) {} if ( finishVersion == null ) {} // Isolation not necessary. Patch files are immutable once written. return LongStream .rangeClosed(startVersion.value(), finishVersion.value()) .mapToObj(v->fetch(fileStore, v)); }
private RDFPatch fetch(FileStore fileStore, long version) { if ( version < getEarliestVersion().value() ) return null; if ( version > getLatestVersion().value() ) return null; try ( InputStream in = fileStore.open((int)version) ) { RDFPatch patch = RDFPatchOps.read(in) ; return patch; } catch ( DeltaNotFoundException ex) // Our internal 404. { return null; } catch (IOException ex) { throw IOX.exception(ex); } }
if ( version != Version.INIT.value() ) { /*msg*/ } if ( current != null ) { /*msg*/ } if ( previous != null ) { /*msg*/ }
public PatchLogInfo getPatchLogInfo() { checkDeltaConnection(); PatchLogInfo info = dLink.getPatchLogInfo(datasourceId); if ( info != null ) { if ( remote.get() != null ) { if ( Version.isValid(getRemoteVersionCached()) && info.getMaxVersion().value() < getRemoteVersionCached().value() ) { String dsName = dLink.getDataSourceName(datasourceId); FmtLog.warn(LOG, "[ds:%s %s] Remote version behind local tracking of remote version: [%d, %d]", datasourceId, dsName, info.getMaxVersion(), getRemoteVersionCached()); } } // Set the local copy whenever we get the remote latest. remote.set(info); } return info; }
/** Send a patch to log server. */ public synchronized void append(RDFPatch patch) { checkDeltaConnection(); Version ver = dLink.append(datasourceId, patch); if ( ! Version.isValid(ver) ) // Didn't happen. return ; Version ver0 = state.version(); if ( ver0.value() >= ver.value() ) FmtLog.warn(LOG, "[%s] Version did not advance: %d -> %d", datasourceId.toString(), ver0 , ver); state.updateState(ver, Id.fromNode(patch.getId())); }
protected void exec1(String fn) { Id dsRef = getDescription().getId(); PatchLogInfo info = dLink.getPatchLogInfo(dsRef); Id prev = info.getLatestPatch(); RDFPatch body = toPatch(fn); // Header. PatchHeader header = RDFPatchOps.makeHeader(Id.create().asNode(), prev==null?null:prev.asNode()); RDFPatch patch = RDFPatchOps.withHeader(header, body); //RDFPatchOps.write(System.out, patch); // Add previous. Version version = dLink.append(dsRef, patch); System.out.printf("Version = %s\n", version.value()); }
@Test public void cmd_mk() { String LOG_NAME = "ABC_1"; cmdq("mk", "--server="+serverURL, LOG_NAME); DataSourceDescription dsd = dLink.getDataSourceDescriptionByName(LOG_NAME); assertNotNull(dsd); assertEquals(LOG_NAME, dsd.getName()); List<DataSourceDescription> list = dLink.listDescriptions(); assertEquals(1, list.size()); DeltaLog log = new DeltaLog(dLink, dsd.getId()); PatchLogInfo info = log.info(); assertEquals(0, log.getCurrentVersion().value()); }
private static void verifyServer(String URL) { DeltaLink dLink = DeltaLinkHTTP.connect(URL); cmdq("mk", "--server="+URL, "ABC"); DataSourceDescription dsd = dLink.getDataSourceDescriptionByName("ABC"); assertNotNull(dsd); cmdq("append", "--server="+URL, "--log=ABC", "testing/data.rdfp"); DeltaLog log = new DeltaLog(dLink, dsd.getId()); PatchLogInfo info = log.info(); assertEquals(1, log.getCurrentVersion().value()); cmdq("fetch", "--server="+URL, "--log=ABC", "1"); cmdq("rm", "--server="+URL, "ABC"); DataSourceDescription dsd1 = dLink.getDataSourceDescriptionByName("ABC"); assertNull(dsd1); } }