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 void
cacheChangeEvent(PropStoreKey<?> propStoreKey)
NOOP for the prop store - the cache value will reflect the updated value on next read.void
connectionEvent()
A ZooKeeper connection event (session closed, expired...) and thatvoid
create(PropStoreKey<?> propStoreKey, Map<String,String> props)
Create an initial entry for the PropCacheId.void
delete(@NonNull PropStoreKey<?> propStoreKey)
Delete the store node from the underlying store.void
deleteEvent(PropStoreKey<?> propStoreKey)
Signal that the node had been deleted from ZooKeeper.boolean
exists(PropStoreKey<?> propStoreKey)
Test that a node for properties exists without throwing a KeeperException.@NonNull VersionedProperties
get(PropStoreKey<?> propStoreKey)
get or create properties from the store.PropCache
getCache()
@Nullable VersionedProperties
getIfCached(PropStoreKey<?> propStoreKey)
PropStoreMetrics
getMetrics()
static ZooPropStore
initialize(@NonNull InstanceId instanceId, @NonNull ZooReaderWriter zrw)
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.static @Nullable VersionedProperties
readFromZk(PropStoreKey<?> propStoreKey, PropStoreWatcher watcher, ZooReader zooReader)
Convenience method for utilities that may not have a PropStore read the encoded properties directly from ZooKeeper.void
registerAsListener(PropStoreKey<?> propStoreKey, PropChangeListener listener)
External processes can register for notifications if the properties change.void
removeProperties(@NonNull PropStoreKey<?> propStoreKey, @NonNull Collection<String> keys)
Deletes individual properties specified by the set of keys.void
replaceAll(@NonNull PropStoreKey<?> propStoreKey, long version, @NonNull Map<String,String> props)
Replaces all current properties with map provided.boolean
validateDataVersion(PropStoreKey<?> storeKey, long expectedVersion)
Compare the stored data version with the expected version.void
zkChangeEvent(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:PropStore
Test 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:PropStore
Create 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:
get
in 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:
putAll
in 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:PropStore
Replaces all current properties with map provided. If a property is not included in the new map, the property will not be set.- Specified by:
replaceAll
in 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:PropStore
Deletes individual properties specified by the set of keys.- Specified by:
removeProperties
in interfacePropStore
- Parameters:
propStoreKey
- the prop cache keykeys
- a set of keys.
-
delete
public void delete(@NonNull PropStoreKey<?> propStoreKey)
Description copied from interface:PropStore
Delete the store node from the underlying store.
-
registerAsListener
public void registerAsListener(PropStoreKey<?> propStoreKey, PropChangeListener listener)
Description copied from interface:PropStore
External 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:
registerAsListener
in interfacePropStore
- Parameters:
propStoreKey
- the prop cache keylistener
- a listener
-
zkChangeEvent
public void zkChangeEvent(PropStoreKey<?> propStoreKey)
Description copied from interface:PropChangeListener
Signal that a ZooKeeper data change event occurred and that the data has changed.- Specified by:
zkChangeEvent
in 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:
cacheChangeEvent
in interfacePropChangeListener
- Parameters:
propStoreKey
- the prop cache id.
-
deleteEvent
public void deleteEvent(PropStoreKey<?> propStoreKey)
Description copied from interface:PropChangeListener
Signal that the node had been deleted from ZooKeeper.- Specified by:
deleteEvent
in interfacePropChangeListener
-
connectionEvent
public void connectionEvent()
Description copied from interface:PropChangeListener
A ZooKeeper connection event (session closed, expired...) and that- Specified by:
connectionEvent
in interfacePropChangeListener
-
getIfCached
public @Nullable VersionedProperties getIfCached(PropStoreKey<?> propStoreKey)
- Specified by:
getIfCached
in interfacePropStore
-
validateDataVersion
public boolean validateDataVersion(PropStoreKey<?> storeKey, long expectedVersion)
Description copied from interface:PropStore
Compare the stored data version with the expected version. Notifies subscribers of the change detection.- Specified by:
validateDataVersion
in interfacePropStore
- Parameters:
storeKey
- specifies key for backend storeexpectedVersion
- the expected data version- Returns:
- true if the stored version matches the provided expected version.
-
-