This is an automated email from the ASF dual-hosted git repository.
ctubbsii pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new 9c1fc91b36 Improve Upgrader11to12 to avoid public API (#5933)
9c1fc91b36 is described below
commit 9c1fc91b360031636d40d22309fa9cc648a0d7b8
Author: Christopher Tubbs <[email protected]>
AuthorDate: Fri Sep 26 16:56:37 2025 -0400
Improve Upgrader11to12 to avoid public API (#5933)
* Avoid public API when looking up namespace names/ids
* Use NamespaceMapping for simpler code
* Update unit test accordingly and give unique test namespace id and
name based on test method name
---
.../accumulo/manager/upgrade/Upgrader11to12.java | 94 ++++++++++------------
.../manager/upgrade/Upgrader11to12Test.java | 30 +++----
2 files changed, 54 insertions(+), 70 deletions(-)
diff --git
a/server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader11to12.java
b/server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader11to12.java
index 7d8dc61ef6..2464c9476b 100644
---
a/server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader11to12.java
+++
b/server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader11to12.java
@@ -39,13 +39,10 @@ import java.util.Set;
import java.util.TreeMap;
import org.apache.accumulo.core.Constants;
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.BatchDeleter;
import org.apache.accumulo.core.client.BatchWriter;
import org.apache.accumulo.core.client.IsolatedScanner;
import org.apache.accumulo.core.client.MutationsRejectedException;
-import org.apache.accumulo.core.client.NamespaceNotFoundException;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.admin.TabletAvailability;
@@ -919,59 +916,52 @@ public class Upgrader11to12 implements Upgrader {
}
void moveTableProperties(ServerContext context) {
- try {
- final SystemPropKey spk = SystemPropKey.of();
- final VersionedProperties sysProps = context.getPropStore().get(spk);
- final Map<String,String> sysTableProps = new HashMap<>();
- sysProps.asMap().entrySet().stream()
- .filter(e -> e.getKey().startsWith(Property.TABLE_PREFIX.getKey()))
- .forEach(e -> sysTableProps.put(e.getKey(), e.getValue()));
- LOG.info("Adding the following table properties to namespaces unless
overridden:");
- sysTableProps.forEach((k, v) -> LOG.info("{} -> {}", k, v));
-
- for (String ns : context.namespaceOperations().list()) {
- final NamespaceId nsid = context.getNamespaceId(ns);
- final NamespacePropKey nsk = NamespacePropKey.of(nsid);
- final Map<String,String> nsProps =
context.getPropStore().get(nsk).asMap();
- final Map<String,String> nsPropAdditions = new HashMap<>();
-
- for (Entry<String,String> e : sysTableProps.entrySet()) {
-
- // Don't move iterators or constraints from the system configuration
- // to the system namespace. This will affect the root and metadata
- // tables.
- if (ns.equals(Namespace.ACCUMULO.name())
- &&
(e.getKey().startsWith(Property.TABLE_ITERATOR_PREFIX.getKey())
- ||
e.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.getKey()))) {
- LOG.debug(
- "Not moving property {} to 'accumulo' namespace, iterator and
constraint properties are ignored on purpose.",
- e.getKey());
- continue;
- }
+ final SystemPropKey spk = SystemPropKey.of();
+ final VersionedProperties sysProps = context.getPropStore().get(spk);
+ final Map<String,String> sysTableProps = new HashMap<>();
+ sysProps.asMap().entrySet().stream()
+ .filter(e -> e.getKey().startsWith(Property.TABLE_PREFIX.getKey()))
+ .forEach(e -> sysTableProps.put(e.getKey(), e.getValue()));
+ LOG.info("Adding the following table properties to namespaces unless
overridden:");
+ sysTableProps.forEach((k, v) -> LOG.info("{} -> {}", k, v));
+
+ context.getNamespaceMapping().getIdToNameMap().forEach((nsid, ns) -> {
+ final NamespacePropKey nsk = NamespacePropKey.of(nsid);
+ final Map<String,String> nsProps =
context.getPropStore().get(nsk).asMap();
+ final Map<String,String> nsPropAdditions = new HashMap<>();
+
+ for (Entry<String,String> e : sysTableProps.entrySet()) {
+
+ // Don't move iterators or constraints from the system configuration
+ // to the system namespace. This will affect the root and metadata
+ // tables.
+ if (ns.equals(Namespace.ACCUMULO.name())
+ && (e.getKey().startsWith(Property.TABLE_ITERATOR_PREFIX.getKey())
+ ||
e.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.getKey()))) {
+ LOG.debug(
+ "Not moving property {} to 'accumulo' namespace, iterator and
constraint properties are ignored on purpose.",
+ e.getKey());
+ continue;
+ }
- final String nsVal = nsProps.get(e.getKey());
- // If it's not set, then add the system table property
- // to the namespace. If it is set, then it doesnt matter
- // what the value is, we can ignore it.
- if (nsVal == null) {
- nsPropAdditions.put(e.getKey(), e.getValue());
- }
+ final String nsVal = nsProps.get(e.getKey());
+ // If it's not set, then add the system table property
+ // to the namespace. If it is set, then it doesnt matter
+ // what the value is, we can ignore it.
+ if (nsVal == null) {
+ nsPropAdditions.put(e.getKey(), e.getValue());
}
- context.getPropStore().putAll(nsk, nsPropAdditions);
- LOG.debug("Added table properties to namespace '{}' id:{}:", ns, nsid);
- nsPropAdditions.forEach((k, v) -> LOG.debug("{} -> {}", k, v));
- LOG.info("Namespace '{}' id:{} completed.", ns, nsid);
}
+ context.getPropStore().putAll(nsk, nsPropAdditions);
+ LOG.debug("Added table properties to namespace '{}' id:{}:", ns, nsid);
+ nsPropAdditions.forEach((k, v) -> LOG.debug("{} -> {}", k, v));
+ LOG.info("Namespace '{}' id:{} completed.", ns, nsid);
+ });
- LOG.info("Removing table properties from system configuration.");
- context.getPropStore().removeProperties(spk, sysTableProps.keySet());
+ LOG.info("Removing table properties from system configuration.");
+ context.getPropStore().removeProperties(spk, sysTableProps.keySet());
- LOG.info(
- "Moving table properties from system configuration to namespace
configurations complete.");
-
- } catch (AccumuloException | AccumuloSecurityException |
NamespaceNotFoundException e) {
- throw new IllegalStateException(
- "Error trying to move table properties from system to namespace", e);
- }
+ LOG.info(
+ "Moving table properties from system configuration to namespace
configurations complete.");
}
}
diff --git
a/server/manager/src/test/java/org/apache/accumulo/manager/upgrade/Upgrader11to12Test.java
b/server/manager/src/test/java/org/apache/accumulo/manager/upgrade/Upgrader11to12Test.java
index 425aa1da5d..f1f1541eb8 100644
---
a/server/manager/src/test/java/org/apache/accumulo/manager/upgrade/Upgrader11to12Test.java
+++
b/server/manager/src/test/java/org/apache/accumulo/manager/upgrade/Upgrader11to12Test.java
@@ -45,7 +45,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import java.util.TreeSet;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -53,7 +52,6 @@ import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.BatchWriter;
import org.apache.accumulo.core.client.MutationsRejectedException;
import org.apache.accumulo.core.client.NamespaceNotFoundException;
-import org.apache.accumulo.core.client.admin.NamespaceOperations;
import org.apache.accumulo.core.clientImpl.Namespace;
import org.apache.accumulo.core.clientImpl.NamespaceMapping;
import org.apache.accumulo.core.conf.Property;
@@ -77,6 +75,7 @@ import
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.La
import
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ScanFileColumnFamily;
import org.apache.accumulo.core.metadata.schema.RootTabletMetadata;
import org.apache.accumulo.core.zookeeper.ZooSession;
+import org.apache.accumulo.manager.WithTestNames;
import org.apache.accumulo.server.ServerContext;
import org.apache.accumulo.server.conf.codec.VersionedProperties;
import org.apache.accumulo.server.conf.store.NamespacePropKey;
@@ -92,7 +91,7 @@ import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class Upgrader11to12Test {
+public class Upgrader11to12Test extends WithTestNames {
private static final Logger LOG =
LoggerFactory.getLogger(Upgrader11to12Test.class);
@@ -589,13 +588,13 @@ public class Upgrader11to12Test {
final VersionedProperties systemNsProps =
createMock(VersionedProperties.class);
final VersionedProperties defaultNsProps =
createMock(VersionedProperties.class);
final VersionedProperties testNsProps =
createMock(VersionedProperties.class);
- final NamespaceOperations nsops = createMock(NamespaceOperations.class);
+ final NamespaceMapping nsmap = createMock(NamespaceMapping.class);
- final TreeSet<String> namespaces = new TreeSet<>();
- namespaces.add(Namespace.ACCUMULO.name());
- namespaces.add(Namespace.DEFAULT.name());
- namespaces.add("test");
- var testNsId = NamespaceId.of("5");
+ var testNsId = NamespaceId.of("nsid_" + testName());
+ var testNsName = "nsname_" + testName();
+ final TreeMap<NamespaceId,String> namespaces =
+ new TreeMap<>(Map.of(Namespace.DEFAULT.id(), Namespace.DEFAULT.name(),
+ Namespace.ACCUMULO.id(), Namespace.ACCUMULO.name(), testNsId,
testNsName));
final Map<String,String> sysProps = new HashMap<>();
sysProps.put(Property.TABLE_BLOOM_ENABLED.getKey(), "true");
@@ -640,13 +639,8 @@ public class Upgrader11to12Test {
expect(propStore.get(SystemPropKey.of())).andReturn(sysVerProps).once();
expect(sysVerProps.asMap()).andReturn(sysProps).once();
- expect(context.namespaceOperations()).andReturn(nsops).once();
-
expect(context.getNamespaceId(Namespace.DEFAULT.name())).andReturn(Namespace.DEFAULT.id())
- .once();
-
expect(context.getNamespaceId(Namespace.ACCUMULO.name())).andReturn(Namespace.ACCUMULO.id())
- .once();
- expect(context.getNamespaceId("test")).andReturn(testNsId).once();
- expect(nsops.list()).andReturn(namespaces).once();
+ expect(context.getNamespaceMapping()).andReturn(nsmap).once();
+ expect(nsmap.getIdToNameMap()).andReturn(namespaces).once();
final NamespacePropKey apk = NamespacePropKey.of(Namespace.ACCUMULO.id());
final NamespacePropKey dpk = NamespacePropKey.of(Namespace.DEFAULT.id());
@@ -672,11 +666,11 @@ public class Upgrader11to12Test {
propStore.removeProperties(SystemPropKey.of(), sysProps.keySet());
- replay(context, propStore, sysVerProps, systemNsProps, defaultNsProps,
testNsProps, nsops);
+ replay(context, propStore, sysVerProps, systemNsProps, defaultNsProps,
testNsProps, nsmap);
new Upgrader11to12().moveTableProperties(context);
- verify(context, propStore, sysVerProps, systemNsProps, defaultNsProps,
testNsProps, nsops);
+ verify(context, propStore, sysVerProps, systemNsProps, defaultNsProps,
testNsProps, nsmap);
}
}