@Override public PatchStore create(LocalServerConfig config) { CuratorFramework client = curator(config); return new PatchStoreZk(client, this); }
/** Short name used in server configuration files to set the default provider via "log_type" */ @Override public String getShortName() { return super.getShortName() + "s3"; }
@Override protected void deleteStore() { // currently, do not delete persistent state. closeStore(); }
private void stateOrInit() { synchronized(lock) { JsonObject obj = getWatchedState(); if ( obj != null ) jsonSetState(obj); else initState(); if ( version == DeltaConst.VERSION_UNSET ) save(DeltaConst.VERSION_INIT, current, previous); } }
@Override public PatchStorage newPatchStorage(DataSourceDescription dsd, PatchStore patchStore, LocalServerConfig configuration) { PatchStoreZk patchStoreZk = (PatchStoreZk)patchStore; String logPath = zkPath(ZkConst.pLogs, dsd.getName()); return new PatchStorageZk(patchStoreZk.getClient(), patchStoreZk.getInstance(), logPath); }
@Override public PatchLogIndex newPatchLogIndex(DataSourceDescription dsd, PatchStore patchStore, LocalServerConfig configuration) { PatchStoreZk patchStoreZk = (PatchStoreZk)patchStore; String logPath = zkPath(ZkConst.pLogs, dsd.getName()); return new PatchLogIndexZk(patchStoreZk.getClient(), patchStoreZk.getInstance(), dsd, logPath); }
private void init() { // Also sets watcher. List<String> names = getWatchLogs(); updateLogChanges(names, false); }
private void syncState() { JsonObject obj = getWatchedState(); if ( obj != null ) jsonSetState(obj); }
private void initState() { runWithLock(()->{ FmtLog.debug(LOG, "initState %s", logName); if ( current == null ) earliestVersion = Version.INIT; version = DeltaConst.VERSION_INIT; save(version, current, previous); }); }
@Override protected PatchStorage patchStorage() { return new PatchStorageZk(client, "0", patches); } }
private List<DataSourceDescription> listDataSourcesZkAll() { return listDataSourcesZkPath(ZkConst.pLogs); }
private String versionPath(Version ver) { return versionPath(ver.value()) ; } private String versionPath(long ver) { return Zk.zkPath(versionsPath, String.format("%08d", ver)); }
@Override protected PatchLog newPatchLog(DataSourceDescription dsd) { synchronized(storeLock) { return create$(dsd); } }
@Override public void syncVersionInfo() { syncState(); }
@Override public void release() { find().forEach(this::delete); } }
@Override public void save(Version version, Id patch, Id prev) { // Should always be called inside the patch lock. save(version.value(), patch, prev); }
private void updateLogChanges(List<String> namesList, boolean watcher) { String label = (watcher?"watcher":"inline"); if ( namesList == null ) { FmtLog.info(LOGZK, "[%s] updateLogChanges[%s] -> null", instance, label); return; } Set<String> x = new HashSet<>(namesList); FmtLog.info(LOGZK, "[%s] updateLogChanges[%s] -> %s", instance, label, x); updateLogChanges(x); }
@Override public List<DataSourceDescription> listDataSources() { FmtLog.debug(LOGZK, "[%d] listDataSources", instance); sync(); return super.listDataSources(); // List<DataSourceDescription> sources = listDataSourcesZk(); // // Would need to atomically set the data registry. // return sources; }
private List<DataSourceDescription> listDataSourcesZk() { return listDataSourcesZkPath(ZkConst.pActiveLogs); }
@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; }