Class ZooPropStore
- java.lang.Object
-
- org.apache.accumulo.server.conf.store.impl.ZooPropStore
-
- All Implemented Interfaces:
PropChangeListener,PropStore
public class ZooPropStore extends Object implements PropStore, PropChangeListener
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcacheChangeEvent(PropStoreKey<?> propStoreKey)NOOP for the prop store - the cache value will reflect the updated value on next read.voidconnectionEvent()A ZooKeeper connection event (session closed, expired...) and thatvoidcreate(PropStoreKey<?> propStoreKey, Map<String,String> props)Create an initial entry for the PropCacheId.voiddelete(@NonNull PropStoreKey<?> propStoreKey)Delete the store node from the underlying store.voiddeleteEvent(PropStoreKey<?> propStoreKey)Signal that the node had been deleted from ZooKeeper.booleanexists(PropStoreKey<?> propStoreKey)Test that a node for properties exists without throwing a KeeperException.@NonNull VersionedPropertiesget(PropStoreKey<?> propStoreKey)get or create properties from the store.PropCachegetCache()@Nullable VersionedPropertiesgetIfCached(PropStoreKey<?> propStoreKey)PropStoreMetricsgetMetrics()static ZooPropStoreinitialize(@NonNull InstanceId instanceId, @NonNull ZooReaderWriter zrw)voidputAll(@NonNull PropStoreKey<?> propStoreKey, @NonNull Map<String,String> props)Copies all mappings from the specified map and into the existing property values and stores them into the backend store.static @Nullable VersionedPropertiesreadFromZk(PropStoreKey<?> propStoreKey, PropStoreWatcher watcher, ZooReader zooReader)Convenience method for utilities that may not have a PropStore read the encoded properties directly from ZooKeeper.voidregisterAsListener(PropStoreKey<?> propStoreKey, PropChangeListener listener)External processes can register for notifications if the properties change.voidremoveProperties(@NonNull PropStoreKey<?> propStoreKey, @NonNull Collection<String> keys)Deletes individual properties specified by the set of keys.voidreplaceAll(@NonNull PropStoreKey<?> propStoreKey, long version, @NonNull Map<String,String> props)Replaces all current properties with map provided.booleanvalidateDataVersion(PropStoreKey<?> storeKey, long expectedVersion)Compare the stored data version with the expected version.voidzkChangeEvent(PropStoreKey<?> propStoreKey)Signal that a ZooKeeper data change event occurred and that the data has changed.
-
-
-
Method Detail
-
initialize
public static ZooPropStore initialize(@NonNull InstanceId instanceId, @NonNull ZooReaderWriter zrw)
-
exists
public boolean exists(PropStoreKey<?> propStoreKey)
Description copied from interface:PropStoreTest that a node for properties exists without throwing a KeeperException.
-
getMetrics
public PropStoreMetrics getMetrics()
-
create
public void create(PropStoreKey<?> propStoreKey, Map<String,String> props)
Description copied from interface:PropStoreCreate an initial entry for the PropCacheId. If properties already exist, they are not modified.
-
get
public @NonNull VersionedProperties get(PropStoreKey<?> propStoreKey)
get or create properties from the store. If the property node does not exist in ZooKeeper, legacy properties exist, they will be converted to the new storage form and naming convention. The legacy properties are deleted once the new node format is written.- Specified by:
getin interfacePropStore- Parameters:
propStoreKey- the prop cache key- Returns:
- The versioned properties.
- Throws:
IllegalStateException- if the updates fails because of an underlying store exception
-
readFromZk
public static @Nullable VersionedProperties readFromZk(PropStoreKey<?> propStoreKey, PropStoreWatcher watcher, ZooReader zooReader) throws IOException, org.apache.zookeeper.KeeperException, InterruptedException
Convenience method for utilities that may not have a PropStore read the encoded properties directly from ZooKeeper. This allows utilities access when there is a ZooKeeper, may there may not be a full instance running. All exception handling is left to the caller.- Parameters:
propStoreKey- the prop cache keywatcher- a prop store watcher that will receive / handle ZooKeeper events.zooReader- a ZooReader with an authenticated session.- Returns:
- the versioned properties or null if the node does not exist.
- Throws:
IOException- if the underlying data from the ZooKeeper node cannot be decoded.org.apache.zookeeper.KeeperException- if a ZooKeeper exception occursInterruptedException- if the ZooKeeper read was interrupted.
-
putAll
public void putAll(@NonNull PropStoreKey<?> propStoreKey, @NonNull Map<String,String> props)
Copies all mappings from the specified map and into the existing property values and stores them into the backend store. New keys are added and keys the may have existed in the current properties are overwritten.If multiple threads attempt to update values concurrently, this method will automatically retry. If the threads are setting different keys / values the result will be the sum of the changes. If the concurrent threads are attempting to set a value(s) for the same key(s), the value(s) will be the set to the values provided by the last thread to complete. The order is indeterminate.
- Specified by:
putAllin interfacePropStore- Parameters:
propStoreKey- the prop cache idprops- a map of property k,v pairs- Throws:
IllegalStateException- if the values cannot be written or if an underlying store exception occurs.
-
replaceAll
public void replaceAll(@NonNull PropStoreKey<?> propStoreKey, long version, @NonNull Map<String,String> props)
Description copied from interface:PropStoreReplaces all current properties with map provided. If a property is not included in the new map, the property will not be set.- Specified by:
replaceAllin interfacePropStore- Parameters:
propStoreKey- the prop cache keyversion- the version of the propertiesprops- a map of property k,v pairs
-
removeProperties
public void removeProperties(@NonNull PropStoreKey<?> propStoreKey, @NonNull Collection<String> keys)
Description copied from interface:PropStoreDeletes individual properties specified by the set of keys.- Specified by:
removePropertiesin interfacePropStore- Parameters:
propStoreKey- the prop cache keykeys- a set of keys.
-
delete
public void delete(@NonNull PropStoreKey<?> propStoreKey)
Description copied from interface:PropStoreDelete the store node from the underlying store.
-
registerAsListener
public void registerAsListener(PropStoreKey<?> propStoreKey, PropChangeListener listener)
Description copied from interface:PropStoreExternal processes can register for notifications if the properties change. Normally processes can read from the store and always receive the current snapshot of the latest values. However, it the process wants to take an active action on change detections, then they can register and receive notifications.Implementation detail - the notification occurs on a separate thread from the underlying store, but listeners should not perform lengthy operations on the notification to prevent delaying other listeners from receive timely notification of the changes detected.
- Specified by:
registerAsListenerin interfacePropStore- Parameters:
propStoreKey- the prop cache keylistener- a listener
-
zkChangeEvent
public void zkChangeEvent(PropStoreKey<?> propStoreKey)
Description copied from interface:PropChangeListenerSignal that a ZooKeeper data change event occurred and that the data has changed.- Specified by:
zkChangeEventin interfacePropChangeListener
-
cacheChangeEvent
public void cacheChangeEvent(PropStoreKey<?> propStoreKey)
NOOP for the prop store - the cache value will reflect the updated value on next read. The change is also sent to external listeners of the need to take action, but for the prop store, no additional action is required.- Specified by:
cacheChangeEventin interfacePropChangeListener- Parameters:
propStoreKey- the prop cache id.
-
deleteEvent
public void deleteEvent(PropStoreKey<?> propStoreKey)
Description copied from interface:PropChangeListenerSignal that the node had been deleted from ZooKeeper.- Specified by:
deleteEventin interfacePropChangeListener
-
connectionEvent
public void connectionEvent()
Description copied from interface:PropChangeListenerA ZooKeeper connection event (session closed, expired...) and that- Specified by:
connectionEventin interfacePropChangeListener
-
getIfCached
public @Nullable VersionedProperties getIfCached(PropStoreKey<?> propStoreKey)
- Specified by:
getIfCachedin interfacePropStore
-
validateDataVersion
public boolean validateDataVersion(PropStoreKey<?> storeKey, long expectedVersion)
Description copied from interface:PropStoreCompare the stored data version with the expected version. Notifies subscribers of the change detection.- Specified by:
validateDataVersionin interfacePropStore- Parameters:
storeKey- specifies key for backend storeexpectedVersion- the expected data version- Returns:
- true if the stored version matches the provided expected version.
-
-