accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwa...@apache.org
Subject [accumulo] branch master updated: #582 - Pass ServerContext to MetadataConstraints (#594)
Date Mon, 13 Aug 2018 14:33:38 GMT
This is an automated email from the ASF dual-hosted git repository.

mwalch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 44e9a70   #582 - Pass ServerContext to MetadataConstraints (#594)
44e9a70 is described below

commit 44e9a702b92e2f52d4201204006aec603288fa65
Author: Mike Walch <mwalch@apache.org>
AuthorDate: Mon Aug 13 10:33:33 2018 -0400

     #582 - Pass ServerContext to MetadataConstraints (#594)
    
    * Created SystemEnvironment and used it to pass ServerContext
---
 .../server/constraints/MetadataConstraints.java    | 12 +++---
 .../server/constraints/SystemEnvironment.java      | 26 +++++++++++
 .../constraints/MetadataConstraintsTest.java       | 50 +++++++++++++---------
 .../org/apache/accumulo/tserver/TabletServer.java  |  8 ++--
 .../accumulo/tserver/TservConstraintEnv.java       | 14 ++++--
 .../accumulo/tserver/TservConstraintEnvTest.java   |  4 +-
 .../accumulo/test/functional/ConstraintIT.java     |  2 +-
 7 files changed, 80 insertions(+), 36 deletions(-)

diff --git a/server/base/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java
b/server/base/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java
index 253ca19..ce9eb3e 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Objects;
 
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.constraints.Constraint;
@@ -107,6 +108,7 @@ public class MetadataConstraints implements Constraint {
 
   @Override
   public List<Short> check(Environment env, Mutation mutation) {
+    final ServerContext context = ((SystemEnvironment)env).getServerContext();
 
     ArrayList<Short> violations = null;
 
@@ -230,7 +232,7 @@ public class MetadataConstraints implements Constraint {
 
             try {
               if (otherTidCount > 0 || !dataFiles.equals(loadedFiles)
-                  || !getArbitrator().transactionAlive(Constants.BULK_ARBITRATOR_TYPE, tid))
{
+                  || !getArbitrator(context).transactionAlive(Constants.BULK_ARBITRATOR_TYPE,
tid)) {
                 violations = addViolation(violations, 8);
               }
             } catch (Exception ex) {
@@ -264,7 +266,7 @@ public class MetadataConstraints implements Constraint {
           }
 
           if (zooRoot == null) {
-            zooRoot = ServerContext.getInstance().getZooKeeperRoot();
+            zooRoot = context.getZooKeeperRoot();
           }
 
           boolean lockHeld = false;
@@ -295,8 +297,9 @@ public class MetadataConstraints implements Constraint {
     return violations;
   }
 
-  protected Arbitrator getArbitrator() {
-    return new ZooArbitrator(ServerContext.getInstance());
+  protected Arbitrator getArbitrator(ServerContext context) {
+    Objects.nonNull(context);
+    return new ZooArbitrator(context);
   }
 
   @Override
@@ -327,5 +330,4 @@ public class MetadataConstraints implements Constraint {
     if (zooCache != null)
       zooCache.clear();
   }
-
 }
diff --git a/server/base/src/main/java/org/apache/accumulo/server/constraints/SystemEnvironment.java
b/server/base/src/main/java/org/apache/accumulo/server/constraints/SystemEnvironment.java
new file mode 100644
index 0000000..185d555
--- /dev/null
+++ b/server/base/src/main/java/org/apache/accumulo/server/constraints/SystemEnvironment.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.server.constraints;
+
+import org.apache.accumulo.core.constraints.Constraint;
+import org.apache.accumulo.server.ServerContext;
+
+public interface SystemEnvironment extends Constraint.Environment {
+
+  ServerContext getServerContext();
+
+}
diff --git a/server/base/src/test/java/org/apache/accumulo/server/constraints/MetadataConstraintsTest.java
b/server/base/src/test/java/org/apache/accumulo/server/constraints/MetadataConstraintsTest.java
index 8b5e7b9..59aa1b6 100644
--- a/server/base/src/test/java/org/apache/accumulo/server/constraints/MetadataConstraintsTest.java
+++ b/server/base/src/test/java/org/apache/accumulo/server/constraints/MetadataConstraintsTest.java
@@ -38,7 +38,7 @@ public class MetadataConstraintsTest {
 
   static class TestMetadataConstraints extends MetadataConstraints {
     @Override
-    protected Arbitrator getArbitrator() {
+    protected Arbitrator getArbitrator(ServerContext context) {
       return new Arbitrator() {
 
         @Override
@@ -56,6 +56,14 @@ public class MetadataConstraintsTest {
     }
   }
 
+  private SystemEnvironment createEnv() {
+    SystemEnvironment env = EasyMock.createMock(SystemEnvironment.class);
+    ServerContext context = EasyMock.createMock(ServerContext.class);
+    EasyMock.expect(env.getServerContext()).andReturn(context);
+    EasyMock.replay(env);
+    return env;
+  }
+
   @Test
   public void testCheck() {
     Logger.getLogger(AccumuloConfiguration.class).setLevel(Level.ERROR);
@@ -64,7 +72,7 @@ public class MetadataConstraintsTest {
 
     MetadataConstraints mc = new MetadataConstraints();
 
-    List<Short> violations = mc.check(null, m);
+    List<Short> violations = mc.check(createEnv(), m);
 
     assertNotNull(violations);
     assertEquals(1, violations.size());
@@ -73,7 +81,7 @@ public class MetadataConstraintsTest {
     m = new Mutation(new Text("0:foo"));
     TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.put(m, new Value("1poo".getBytes()));
 
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
 
     assertNotNull(violations);
     assertEquals(1, violations.size());
@@ -82,7 +90,7 @@ public class MetadataConstraintsTest {
     m = new Mutation(new Text("0;foo"));
     m.put(new Text("bad_column_name"), new Text(""), new Value("e".getBytes()));
 
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
 
     assertNotNull(violations);
     assertEquals(1, violations.size());
@@ -91,7 +99,7 @@ public class MetadataConstraintsTest {
     m = new Mutation(new Text("!!<"));
     TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.put(m, new Value("1poo".getBytes()));
 
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
 
     assertNotNull(violations);
     assertEquals(2, violations.size());
@@ -101,7 +109,7 @@ public class MetadataConstraintsTest {
     m = new Mutation(new Text("0;foo"));
     TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.put(m, new Value("".getBytes()));
 
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
 
     assertNotNull(violations);
     assertEquals(1, violations.size());
@@ -110,21 +118,21 @@ public class MetadataConstraintsTest {
     m = new Mutation(new Text("0;foo"));
     TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.put(m, new Value("bar".getBytes()));
 
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
 
     assertNull(violations);
 
     m = new Mutation(new Text("!0<"));
     TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.put(m, new Value("bar".getBytes()));
 
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
 
     assertNull(violations);
 
     m = new Mutation(new Text("!1<"));
     TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.put(m, new Value("bar".getBytes()));
 
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
 
     assertNotNull(violations);
     assertEquals(1, violations.size());
@@ -144,7 +152,7 @@ public class MetadataConstraintsTest {
         new Value("12345".getBytes()));
     m.put(DataFileColumnFamily.NAME, new Text("/someFile"),
         new DataFileValue(1, 1).encodeAsValue());
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNotNull(violations);
     assertEquals(1, violations.size());
     assertEquals(Short.valueOf((short) 8), violations.get(0));
@@ -155,7 +163,7 @@ public class MetadataConstraintsTest {
         new Value("9".getBytes()));
     m.put(DataFileColumnFamily.NAME, new Text("/someFile"),
         new DataFileValue(1, 1).encodeAsValue());
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNotNull(violations);
     assertEquals(1, violations.size());
     assertEquals(Short.valueOf((short) 8), violations.get(0));
@@ -166,14 +174,14 @@ public class MetadataConstraintsTest {
         new Value("5".getBytes()));
     m.put(DataFileColumnFamily.NAME, new Text("/someFile"),
         new DataFileValue(1, 1).encodeAsValue());
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNull(violations);
 
     // active txid w/o file
     m = new Mutation(new Text("0;foo"));
     m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"),
         new Value("5".getBytes()));
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNotNull(violations);
     assertEquals(1, violations.size());
     assertEquals(Short.valueOf((short) 8), violations.get(0));
@@ -188,7 +196,7 @@ public class MetadataConstraintsTest {
         new Value("7".getBytes()));
     m.put(DataFileColumnFamily.NAME, new Text("/someFile2"),
         new DataFileValue(1, 1).encodeAsValue());
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNotNull(violations);
     assertEquals(1, violations.size());
     assertEquals(Short.valueOf((short) 8), violations.get(0));
@@ -203,7 +211,7 @@ public class MetadataConstraintsTest {
         new Value("5".getBytes()));
     m.put(DataFileColumnFamily.NAME, new Text("/someFile2"),
         new DataFileValue(1, 1).encodeAsValue());
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNull(violations);
 
     // two loaded w/ one active txid and one file
@@ -214,7 +222,7 @@ public class MetadataConstraintsTest {
         new DataFileValue(1, 1).encodeAsValue());
     m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile2"),
         new Value("5".getBytes()));
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNotNull(violations);
     assertEquals(1, violations.size());
     assertEquals(Short.valueOf((short) 8), violations.get(0));
@@ -224,7 +232,7 @@ public class MetadataConstraintsTest {
     m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"),
         new Value("5".getBytes()));
     TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.put(m, new Value("/t1".getBytes()));
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNull(violations);
 
     // inactive txid, mutation that looks like split
@@ -232,7 +240,7 @@ public class MetadataConstraintsTest {
     m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"),
         new Value("12345".getBytes()));
     TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.put(m, new Value("/t1".getBytes()));
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNull(violations);
 
     // active txid, mutation that looks like a load
@@ -241,7 +249,7 @@ public class MetadataConstraintsTest {
         new Value("5".getBytes()));
     m.put(TabletsSection.CurrentLocationColumnFamily.NAME, new Text("789"),
         new Value("127.0.0.1:9997".getBytes()));
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNull(violations);
 
     // inactive txid, mutation that looks like a load
@@ -250,13 +258,13 @@ public class MetadataConstraintsTest {
         new Value("12345".getBytes()));
     m.put(TabletsSection.CurrentLocationColumnFamily.NAME, new Text("789"),
         new Value("127.0.0.1:9997".getBytes()));
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNull(violations);
 
     // deleting a load flag
     m = new Mutation(new Text("0;foo"));
     m.putDelete(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"));
-    violations = mc.check(null, m);
+    violations = mc.check(createEnv(), m);
     assertNull(violations);
 
   }
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
index 9d9b3a1..0451a86 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
@@ -902,7 +902,7 @@ public class TabletServer implements Runnable {
       if (updateMetrics.isEnabled())
         updateMetrics.add(TabletServerUpdateMetrics.PERMISSION_ERRORS, 0);
 
-      UpdateSession us = new UpdateSession(new TservConstraintEnv(security, credentials),
+      UpdateSession us = new UpdateSession(new TservConstraintEnv(context, security, credentials),
           credentials, durability);
       return sessionManager.createSession(us, false);
     }
@@ -1268,8 +1268,8 @@ public class TabletServer implements Runnable {
         final Span prep = Trace.start("prep");
         CommitSession cs;
         try {
-          cs = tablet.prepareMutationsForCommit(new TservConstraintEnv(security, credentials),
-              mutations);
+          cs = tablet.prepareMutationsForCommit(
+              new TservConstraintEnv(context, security, credentials), mutations);
         } finally {
           prep.stop();
         }
@@ -1379,7 +1379,7 @@ public class TabletServer implements Runnable {
               if (mutations.size() > 0) {
 
                 CommitSession cs = tablet.prepareMutationsForCommit(
-                    new TservConstraintEnv(security, sess.credentials), mutations);
+                    new TservConstraintEnv(context, security, sess.credentials), mutations);
 
                 if (cs == null) {
                   for (ServerConditionalMutation scm : entry.getValue())
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TservConstraintEnv.java
b/server/tserver/src/main/java/org/apache/accumulo/tserver/TservConstraintEnv.java
index 3e65518..7f068c9 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TservConstraintEnv.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TservConstraintEnv.java
@@ -20,22 +20,25 @@ import java.nio.ByteBuffer;
 import java.util.Collections;
 
 import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
-import org.apache.accumulo.core.constraints.Constraint.Environment;
 import org.apache.accumulo.core.data.ByteSequence;
 import org.apache.accumulo.core.data.impl.KeyExtent;
 import org.apache.accumulo.core.security.AuthorizationContainer;
 import org.apache.accumulo.core.security.Authorizations;
 import org.apache.accumulo.core.security.thrift.TCredentials;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.constraints.SystemEnvironment;
 import org.apache.accumulo.server.security.SecurityOperation;
 
-public class TservConstraintEnv implements Environment {
+public class TservConstraintEnv implements SystemEnvironment {
 
+  private final ServerContext context;
   private final TCredentials credentials;
   private final SecurityOperation security;
   private Authorizations auths;
   private KeyExtent ke;
 
-  TservConstraintEnv(SecurityOperation secOp, TCredentials credentials) {
+  TservConstraintEnv(ServerContext context, SecurityOperation secOp, TCredentials credentials)
{
+    this.context = context;
     this.security = secOp;
     this.credentials = credentials;
   }
@@ -80,4 +83,9 @@ public class TservConstraintEnv implements Environment {
       }
     };
   }
+
+  @Override
+  public ServerContext getServerContext() {
+    return context;
+  }
 }
diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/TservConstraintEnvTest.java
b/server/tserver/src/test/java/org/apache/accumulo/tserver/TservConstraintEnvTest.java
index e84e415..527b231 100644
--- a/server/tserver/src/test/java/org/apache/accumulo/tserver/TservConstraintEnvTest.java
+++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/TservConstraintEnvTest.java
@@ -50,8 +50,8 @@ public class TservConstraintEnvTest {
     replay(security);
 
     assertTrue(
-        new TservConstraintEnv(security, goodCred).getAuthorizationsContainer().contains(bs));
+        new TservConstraintEnv(null, security, goodCred).getAuthorizationsContainer().contains(bs));
     assertFalse(
-        new TservConstraintEnv(security, badCred).getAuthorizationsContainer().contains(bs));
+        new TservConstraintEnv(null, security, badCred).getAuthorizationsContainer().contains(bs));
   }
 }
diff --git a/test/src/main/java/org/apache/accumulo/test/functional/ConstraintIT.java b/test/src/main/java/org/apache/accumulo/test/functional/ConstraintIT.java
index 4d67fe7..a142f85 100644
--- a/test/src/main/java/org/apache/accumulo/test/functional/ConstraintIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/functional/ConstraintIT.java
@@ -51,7 +51,7 @@ public class ConstraintIT extends AccumuloClusterHarness {
 
   @Override
   protected int defaultTimeoutSeconds() {
-    return 30;
+    return 60;
   }
 
   @Test


Mime
View raw message