public boolean isNil() { return this.equals(nilId); }
@Override public boolean equals(Object obj) { if ( this == obj ) return true; if ( obj == null ) return false; if ( getClass() != obj.getClass() ) return false; DataSourceDescription other = (DataSourceDescription)obj; if ( id == null ) { if ( other.id != null ) return false; } else if ( !id.equals(other.id) ) return false; if ( uri == null ) { if ( other.uri != null ) return false; } else if ( !uri.equals(other.uri) ) return false; return true; }
@Override public boolean equals(Object obj) { if ( this == obj ) return true; if ( obj == null ) return false; if ( getClass() != obj.getClass() ) return false; PatchInfo other = (PatchInfo)obj; if ( patch == null ) { if ( other.patch != null ) return false; } else if ( !patch.equals(other.patch) ) return false; if ( previous == null ) { if ( other.previous != null ) return false; } else if ( !previous.equals(other.previous) ) return false; if ( version == null ) { if ( other.version != null ) return false; } else if ( !version.equals(other.version) ) return false; return true; }
if ( other.latestPatch != null ) return false; } else if ( !latestPatch.equals(other.latestPatch) ) return false; if ( maxVersion == null ) {
@Test public void local_server_restart_01() { Location loc = Location.create(DIR); LocalServer server1 = LocalServers.createFile(DIR); assertEquals(2, server1.listDataSources().size()); Id newId1 = server1.createDataSource("AXYZ", "http://example/axyz"); LocalServer.release(server1); LocalServer server2 = LocalServers.createFile(DIR); // 3 - data1, data2 and the new XYZ. assertEquals(3, server2.listDataSources().size()); assertEquals(3, server2.listDataSourcesIds().size()); long z = server2.listDataSourcesIds().stream().filter(id->id.equals(newId1)).count(); assertEquals("Count of newId occurences", 1, z); Id id = server2.listDataSourcesIds().stream().filter(_id->_id.equals(newId1)).findFirst().get(); assertEquals(newId1, id) ; List<Id> ids = server2.listDataSources().stream().map(dss->dss.getId()).collect(Collectors.toList()); assertTrue(ids.contains(newId1)); }
if ( ! isEmpty() && getLatestId().equals(patchId) ) { return getLatestVersion();
@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; }); }
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 DataSource createDataSource$(int C, PatchStore patchStore, DataSourceDescription dsd) { synchronized(serverLock) { // Server lock, not cluster lock. DataRegistry reg = syncedDataRegistry(); if ( reg.containsName(dsd.getName()) ) { FmtLog.info(LOG, "(%d) Existing: %s", C, dsd); DataSource ds = reg.getByName(dsd.getName()); return ds; } PatchLog patchLog = patchStore.createLog(dsd); // -- DEV // May not be id in DSD - the prev test was not in a cluster lock but patchStore.createLog is atomic ("createOrGet") if ( ! patchLog.getLogId().equals(dsd.getId()) ) { if ( reg.containsName(dsd.getName()) ) { FmtLog.info(LOG, "(%d) Existing1: %s -> %s", C, dsd, patchLog.getDescription()); DataSource ds = reg.getByName(dsd.getName()); FmtLog.info(LOG, "(%d) Existing2: %s -> %s", C, dsd, ds.getDescription()); return ds; } LOG.error("Existing but not found again: "+dsd+" : patch ="+patchLog.getDescription()); } // -- DEV FmtLog.info(LOG, "(%d) New: %s", C, dsd); DataSource newDataSource = new DataSource(dsd, patchLog); // XXX Isn't this done in PatchStore.createPatchLog as well? reg.put(dsd.getId(), newDataSource); return newDataSource; } }