Class InstanceOperationsImpl
- java.lang.Object
-
- org.apache.accumulo.core.clientImpl.InstanceOperationsImpl
-
- All Implemented Interfaces:
InstanceOperations
public class InstanceOperationsImpl extends Object implements InstanceOperations
Provides a class for administering the accumulo instance
-
-
Constructor Summary
Constructors Constructor Description InstanceOperationsImpl(ClientContext context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description List<ActiveCompaction>
getActiveCompactions()
List all internal and external compactions running in Accumulo.List<ActiveCompaction>
getActiveCompactions(String tserver)
List the active compaction running on a tablet server.List<ActiveScan>
getActiveScans(String tserver)
List the active scans on a tablet server.InstanceId
getInstanceId()
Returns a unique ID object that identifies this instance of accumulo.String
getInstanceID()
Deprecated.List<String>
getManagerLocations()
Returns the location(s) of the accumulo manager and any redundant servers.Set<String>
getScanServers()
Returns the locations of the active scan serversMap<String,String>
getSiteConfiguration()
Retrieve the site configuration (that is set in the server configuration file).Map<String,String>
getSystemConfiguration()
Retrieve the system-wide configuration.List<String>
getTabletServers()
List the currently active tablet servers participating in the accumulo instancestatic String
lookupInstanceName(ZooCache zooCache, InstanceId instanceId)
Given a zooCache and instanceId, look up the instance name.Map<String,String>
modifyProperties(Consumer<Map<String,String>> mapMutator)
Modify system properties using a Consumer that accepts a mutable map containing the current system property overrides stored in ZooKeeper.void
ping(String tserver)
Throws an exception if a tablet server can not be contacted.void
removeProperty(String property)
Removes a system property from zookeeper.void
setProperty(String property, String value)
Sets a system property in zookeeper.boolean
testClassLoad(String className, String asTypeName)
Test to see if the instance can load the given class as the given type.void
waitForBalance()
Waits for the tablet balancer to run and return no migrations.
-
-
-
Constructor Detail
-
InstanceOperationsImpl
public InstanceOperationsImpl(ClientContext context)
-
-
Method Detail
-
setProperty
public void setProperty(String property, String value) throws AccumuloException, AccumuloSecurityException, IllegalArgumentException
Description copied from interface:InstanceOperations
Sets a system property in zookeeper. Tablet servers will pull this setting and override the equivalent setting in accumulo.properties. Changes can be seen usingInstanceOperations.getSystemConfiguration()
.Only some properties can be changed by this method, an IllegalArgumentException will be thrown if there is an attempt to set a read-only property.
- Specified by:
setProperty
in interfaceInstanceOperations
- Parameters:
property
- the name of a system propertyvalue
- the value to set a system property to- Throws:
AccumuloException
- if a general error occursAccumuloSecurityException
- if the user does not have permissionIllegalArgumentException
-
modifyProperties
public Map<String,String> modifyProperties(Consumer<Map<String,String>> mapMutator) throws AccumuloException, AccumuloSecurityException, IllegalArgumentException
Description copied from interface:InstanceOperations
Modify system properties using a Consumer that accepts a mutable map containing the current system property overrides stored in ZooKeeper. If the supplied Consumer alters the map without throwing an Exception, then the resulting map will atomically replace the current system property overrides in ZooKeeper. Only properties which can be stored in ZooKeeper will be accepted.Accumulo has multiple layers of properties that for many APIs and SPIs are presented as a single merged view. This API does not offer that merged view, it only offers the properties set at the system layer to the mapMutator.
This new API offers two distinct advantages over the older
InstanceOperations.setProperty(String, String)
API. The older API offered the ability to unconditionally set a single property. This new API offers the following.- Ability to unconditionally set multiple properties atomically. If five properties are mutated by this API, then eventually all of the servers will see those changes all at once. This is really important for configuring something like a scan iterator that requires setting multiple properties.
- Ability to conditionally set multiple properties atomically. With this new API a snapshot of the current instance configuration is passed in to the mapMutator. Code can inspect the current config and decide what if any changes it would like to make. If the config changes while mapMutator is doing inspection and modification, then those actions will be ignored and it will be called again with the latest snapshot of the config.
Below is an example of using this API to conditionally set some instance properties. If while trying to set the compaction planner properties another process modifies the manager balancer properties, then it would automatically retry and call the lambda again with the latest snapshot of instance properties.
AccumuloClient client = getClient(); Map<String,String> acceptedProps = client.instanceOperations().modifyProperties(currProps -> { var planner = currProps.get("tserver.compaction.major.service.default.planner"); //This code will only change the compaction planner if its currently set to default settings. //The endsWith() function was used to make the example short, would be better to use equals(). if(planner != null && planner.endsWith("DefaultCompactionPlanner") { // tservers will eventually see these compaction planner changes and when they do they will see all of the changes at once currProps.keySet().removeIf( prop -> prop.startsWith("tserver.compaction.major.service.default.planner.opts.")); currProps.put("tserver.compaction.major.service.default.planner","MyPlannerClassName"); currProps.put("tserver.compaction.major.service.default.planner.opts.myOpt1","val1"); currProps.put("tserver.compaction.major.service.default.planner.opts.myOpt2","val2"); } }); // Since three properties were set may want to check for the values of all // three, just checking one in this example to keep it short. if("MyPlannerClassName".equals(acceptedProps.get("tserver.compaction.major.service.default.planner"))){ // the compaction planner change was accepted or already existed, so take action for that outcome } else { // the compaction planner change was not done, so take action for that outcome }
}- Specified by:
modifyProperties
in interfaceInstanceOperations
- Parameters:
mapMutator
- This consumer should modify the passed snapshot of instance properties to contain the desired keys and values. It should be safe for Accumulo to call this consumer multiple times, this may be done automatically when certain retryable errors happen. The consumer should probably avoid accessing the Accumulo client as that could lead to undefined behavior.- Returns:
- The map that became Accumulo's new properties for this table. This map is immutable and contains the snapshot passed to mapMutator and the changes made by mapMutator.
- Throws:
AccumuloException
- if a general error occursAccumuloSecurityException
- if the user does not have permissionIllegalArgumentException
- if the Consumer alters the map by adding properties that cannot be stored in ZooKeeper
-
removeProperty
public void removeProperty(String property) throws AccumuloException, AccumuloSecurityException
Description copied from interface:InstanceOperations
Removes a system property from zookeeper. Changes can be seen usingInstanceOperations.getSystemConfiguration()
- Specified by:
removeProperty
in interfaceInstanceOperations
- Parameters:
property
- the name of a system property- Throws:
AccumuloException
- if a general error occursAccumuloSecurityException
- if the user does not have permission
-
getSystemConfiguration
public Map<String,String> getSystemConfiguration() throws AccumuloException, AccumuloSecurityException
Description copied from interface:InstanceOperations
Retrieve the system-wide configuration.- Specified by:
getSystemConfiguration
in interfaceInstanceOperations
- Returns:
- A map of system properties set in zookeeper. If a property is not set in zookeeper, then it will return the value set in accumulo.properties on some server. If nothing is set in an accumulo.properties file, the default value for each property will be used.
- Throws:
AccumuloException
AccumuloSecurityException
-
getSiteConfiguration
public Map<String,String> getSiteConfiguration() throws AccumuloException, AccumuloSecurityException
Description copied from interface:InstanceOperations
Retrieve the site configuration (that is set in the server configuration file).- Specified by:
getSiteConfiguration
in interfaceInstanceOperations
- Returns:
- A map of system properties set in accumulo.properties on some server. If nothing is set in an accumulo.properties file, the default value for each property will be used.
- Throws:
AccumuloException
AccumuloSecurityException
-
getManagerLocations
public List<String> getManagerLocations()
Description copied from interface:InstanceOperations
Returns the location(s) of the accumulo manager and any redundant servers.- Specified by:
getManagerLocations
in interfaceInstanceOperations
- Returns:
- a list of locations in
hostname:port
form.
-
getScanServers
public Set<String> getScanServers()
Description copied from interface:InstanceOperations
Returns the locations of the active scan servers- Specified by:
getScanServers
in interfaceInstanceOperations
- Returns:
- A set of currently active scan servers.
-
getTabletServers
public List<String> getTabletServers()
Description copied from interface:InstanceOperations
List the currently active tablet servers participating in the accumulo instance- Specified by:
getTabletServers
in interfaceInstanceOperations
- Returns:
- A list of currently active tablet servers.
-
getActiveScans
public List<ActiveScan> getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException
Description copied from interface:InstanceOperations
List the active scans on a tablet server.- Specified by:
getActiveScans
in interfaceInstanceOperations
- Parameters:
tserver
- The tablet server address. This should be of the form<ip address>:<port>
- Returns:
- A list of active scans on tablet server.
- Throws:
AccumuloException
AccumuloSecurityException
-
testClassLoad
public boolean testClassLoad(String className, String asTypeName) throws AccumuloException, AccumuloSecurityException
Description copied from interface:InstanceOperations
Test to see if the instance can load the given class as the given type. This check does not consider per table classpaths, seeTableOperations.testClassLoad(String, String, String)
- Specified by:
testClassLoad
in interfaceInstanceOperations
- Returns:
- true if the instance can load the given class as the given type, false otherwise
- Throws:
AccumuloException
AccumuloSecurityException
-
getActiveCompactions
public List<ActiveCompaction> getActiveCompactions(String tserver) throws AccumuloException, AccumuloSecurityException
Description copied from interface:InstanceOperations
List the active compaction running on a tablet server. Using this method withInstanceOperations.getTabletServers()
will only show compactions running on tservers, leaving out any external compactions running on compactors. UseInstanceOperations.getActiveCompactions()
to get a list of all compactions running on tservers and compactors.- Specified by:
getActiveCompactions
in interfaceInstanceOperations
- Parameters:
tserver
- The tablet server address. This should be of the form<ip address>:<port>
- Returns:
- the list of active compactions
- Throws:
AccumuloException
AccumuloSecurityException
-
getActiveCompactions
public List<ActiveCompaction> getActiveCompactions() throws AccumuloException, AccumuloSecurityException
Description copied from interface:InstanceOperations
List all internal and external compactions running in Accumulo.- Specified by:
getActiveCompactions
in interfaceInstanceOperations
- Returns:
- the list of active compactions
- Throws:
AccumuloException
AccumuloSecurityException
-
ping
public void ping(String tserver) throws AccumuloException
Description copied from interface:InstanceOperations
Throws an exception if a tablet server can not be contacted.- Specified by:
ping
in interfaceInstanceOperations
- Parameters:
tserver
- The tablet server address. This should be of the form<ip address>:<port>
- Throws:
AccumuloException
-
waitForBalance
public void waitForBalance() throws AccumuloException
Description copied from interface:InstanceOperations
Waits for the tablet balancer to run and return no migrations.- Specified by:
waitForBalance
in interfaceInstanceOperations
- Throws:
AccumuloException
-
lookupInstanceName
public static String lookupInstanceName(ZooCache zooCache, InstanceId instanceId)
Given a zooCache and instanceId, look up the instance name.
-
getInstanceID
@Deprecated(since="2.1.0") public String getInstanceID()
Deprecated.Description copied from interface:InstanceOperations
Returns a unique string that identifies this instance of accumulo.- Specified by:
getInstanceID
in interfaceInstanceOperations
- Returns:
- a String
-
getInstanceId
public InstanceId getInstanceId()
Description copied from interface:InstanceOperations
Returns a unique ID object that identifies this instance of accumulo.- Specified by:
getInstanceId
in interfaceInstanceOperations
- Returns:
- an InstanceId
-
-