@Override public PatchStore create(LocalServerConfig config) { CuratorFramework client = curator(config); return new PatchStoreZk(client, this); }
@Override protected void sync() { //FmtLog.debug(LOGZK, "[%s] Store sync", instance); try { List<String> logNames = activeLogs(); //FmtLog.debug(LOGZK, "[%s] Store sync : %s", instance, logNames); updateLogChanges(logNames, false); } catch (Exception ex) { FmtLog.warn(LOGZK, "Exception in sync: "+ex.getClass().getSimpleName()+" "+ex.getMessage()); } }
@Override protected void deleteStore() { // currently, do not delete persistent state. closeStore(); }
@Override protected List<DataSourceDescription> initialize(LocalServerConfig config) { if ( client == null ) { FmtLog.warn(LOGZK, "[%s] Format new PatchStoreZk", instance); return Collections.emptyList(); } connectToZookeeper(); boolean isEmpty = zkCalc(()->client.checkExists().forPath(ZkConst.pRoot)==null); try { if ( isEmpty ) { FmtLog.info(LOGZK, "[%s] Format new PatchStoreZk", instance); formatPatchStore(client); } else init(); getWatchLogs(); } catch (Exception ex) { LOGZK.error("Failed to initialize from the persistent state: "+ex.getMessage(), ex); return Collections.emptyList(); } return listDataSourcesZk(); }
if ( ! validateName(dsName) ) { String msg = String.format("Log name '%s' does not match regex '%s'", dsName, LogNameRegex); Log.warn(LOGZK, msg); if ( ! zkExists(client, logPath) ) { FmtLog.debug(LOGZK, "[%d] Does not exist: format", instance); clusterLock(()->{ return; formatPatchLog(client, dsd, 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); }
createPatchLog(dsd); }); if ( patchLog == null ) return; releasePatchLog(patchLog.getLogId()); });
@Override protected PatchLog newPatchLog(DataSourceDescription dsd) { synchronized(storeLock) { return create$(dsd); } }
@Override protected void delete(PatchLog patchLog) { clusterLock(()->{ String dsName = patchLog.getDescription().getName(); PatchLog patchLog2 = patchLogs.remove(dsName); if ( patchLog2 == null ) // Already gone. return; FmtLog.info(LOGZK, "[%s] delete patch log '%s'", instance, dsName); // Remove from activeLogs, leave in the "logs" area. // This triggers watchers. String zkActiveLog = zkPath(ZkConst.pActiveLogs, dsName); if ( zkExists(client, zkActiveLog) ) { zkDelete(client, zkActiveLog); } String logPath = zkPath(ZkConst.pLogs, dsName); // Clear up. zkDelete(client, logPath); }, null); }
@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); }