/** Is this version a possible version? (i.e. not a marker) */ public static boolean isValid(Version version) { if ( version == null ) return false; return version.isValid(); }
@Override public Stream<RDFPatch> range(Version start, Version finish) { if ( ! Version.isValid(start) ) throw new DeltaException("Bad start version : "+start); if ( ! Version.isValid(finish) ) throw new DeltaException("Bad finish version : "+finish); // Isolation not necessary. Patch files are immutable once written. return range$(start, finish); }
public Version inc() { if ( this == INIT ) return FIRST; if ( ! isValid() ) throw new DeltaException("Attempt to get inc version on a non-version number: "+this); return Version.create(version+1); }
@Override public RDFPatch fetch(Id dsRef, Version version) { if ( !Version.isValid(version) ) return null; return fetchCommon(dsRef, DeltaConst.paramVersion, version.asParam()); }
private void newState(long newVersion, Id patch, Id prev) { synchronized(lock) { FmtLog.debug(LOG, "newVersion %d -> %d", version, newVersion); //FmtLog.info(LOG, "[%s] newState %s -> %s", instance, Version.str(version), Version.str(newVersion)); if ( newVersion <= version ) { if ( newVersion == version ) { if ( ! Objects.equals(patch, current) || ! Objects.equals(prev,previous) ) FmtLog.error(LOG, "Same version but different ids: current=(%s,%s), proposed=(%s,%s)", current, previous, patch, prev); } return ; } //FmtLog.debug(LOG, "-- [%d] State: [%s] (%s, %s, %s)", instance, dsd.getName(), version, current, previous); if ( newVersion == DeltaConst.VERSION_FIRST && ! earliestVersion.isValid() ) { // If going no patch -> patch, set the start. earliestVersion = Version.FIRST; earliestId = patch; } // newVersion > version this.version = newVersion; this.current = patch; this.previous = prev; } }
@Override public Id getEarliestId() { Version x = getEarliestVersion(); if ( ! Version.isValid(x) ) return null; return idToVersion.inverse().get(x); }
@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; }
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; }
@Override protected void execCmd() { if ( getPositional().isEmpty() ) { Id dsRef = getDescription().getId(); PatchLogInfo logInfo = dLink.getPatchLogInfo(dsRef); if ( ! logInfo.getMaxVersion().isValid()) { throw new CmdException(getCommandName()+" : Empty log"); } exec1(logInfo.getMaxVersion()); return ; } getPositional().forEach(v->{ long patchVersion; try { patchVersion = Integer.parseInt(v); } catch (NumberFormatException ex) { throw new CmdException(getCommandName()+" : Invalid version"); } exec1(Version.create(patchVersion)); }); }
if ( ! Version.isValid(version) ) { LOG.warn("No version: "+JSON.toStringFlat(sourceObj));
/** 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())); }
private void detailsByDSD(DataSourceDescription dsd) { PatchLogInfo logInfo = dLink.getPatchLogInfo(dsd.getId()); if ( logInfo == null ) { // Some thing bad somewhere. System.out.printf("[%s %s <%s> [no info] %s]\n", dsd.getId(), dsd.getName(), dsd.getUri()); return; } if ( Version.INIT.equals(logInfo.getMinVersion()) && Version.INIT.equals(logInfo.getMaxVersion()) ) { if ( logInfo.getLatestPatch() != null ) // Should not happen. System.out.printf("[%s %s <%s> [empty] %s]\n", dsd.getId(), dsd.getName(), dsd.getUri(), logInfo.getLatestPatch().toString()); else System.out.printf("[%s %s <%s> [empty]]\n", dsd.getId(), dsd.getName(), dsd.getUri()); return; } if ( logInfo.getMinVersion().isValid() ) { System.out.printf("[%s %s <%s> [%s,%s] %s]\n", dsd.getId(), dsd.getName(), dsd.getUri(), logInfo.getMinVersion(), logInfo.getMaxVersion(), (logInfo.getLatestPatch()==null)?"<no patches>":logInfo.getLatestPatch().toString() ); } }
/** 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); }