keith-turner commented on code in PR #3563:
URL: https://github.com/apache/accumulo/pull/3563#discussion_r1251215955


##########
server/base/src/main/java/org/apache/accumulo/server/metadata/RefreshesImpl.java:
##########
@@ -0,0 +1,237 @@
+/*
+ * 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
+ *
+ *   https://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.metadata;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static 
org.apache.accumulo.core.metadata.RootTable.ZROOT_TABLET_REFRESHES;
+import static org.apache.accumulo.core.util.LazySingletons.GSON;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.metadata.RootTable;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.core.metadata.schema.ExternalCompactionId;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.RefreshSection;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.hadoop.io.Text;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public class RefreshesImpl implements Ample.Refreshes {
+
+  private static final Logger log = 
LoggerFactory.getLogger(RefreshesImpl.class);
+
+  private final Ample.DataLevel dataLevel;
+  private final ServerContext context;
+
+  public static String getInitialJson() {
+    return toJson(Map.of());
+  }
+
+  // This class is used to serialize and deserialize root tablet metadata 
using GSon. Any changes to
+  // this class must consider persisted data.
+  private static class Data {
+    final int version;
+
+    final Map<String,String> entries;
+
+    public Data(int version, Map<String,String> entries) {
+      this.version = version;
+      this.entries = entries;
+    }
+  }
+
+  private static String toJson(Map<String,String> entries) {
+    var data = new Data(1, Objects.requireNonNull(entries));
+    return GSON.get().toJson(data, Data.class);
+  }
+
+  private Map<String,String> fromJson(String json) {
+    Data data = GSON.get().fromJson(json, Data.class);
+    Preconditions.checkArgument(data.version == 1);
+    Objects.requireNonNull(data.entries);
+    return data.entries;
+  }
+
+  public RefreshesImpl(ServerContext context, Ample.DataLevel dataLevel) {
+    this.context = context;
+    this.dataLevel = dataLevel;
+  }
+
+  private void mutateRootRefreshes(Consumer<Map<String,String>> mutator) {
+    String zpath = context.getZooKeeperRoot() + ZROOT_TABLET_REFRESHES;
+    try {
+      context.getZooReaderWriter().mutateExisting(zpath, currVal -> {
+        String currJson = new String(currVal, UTF_8);
+        log.debug("Root refreshes before change : {}", currJson);
+        Map<String,String> entries = fromJson(currJson);
+        mutator.accept(entries);
+        String newJson = toJson(entries);
+        log.debug("Root refreshes after change  : {}", newJson);
+        if (newJson.length() > 262_144) {
+          log.warn("Root refreshes stored in ZK at {} are getting large ({} 
bytes)."
+              + " Large nodes may cause problems for Zookeeper!", zpath, 
newJson.length());
+        }
+        return newJson.getBytes(UTF_8);
+      });
+    } catch (Exception e) {
+      throw new IllegalStateException(e);
+    }
+  }
+
+  private Text createRow(RefreshEntry entry) {
+    return new Text(RefreshSection.getRowPrefix() + 
entry.getEcid().canonical());
+  }
+
+  private Mutation createAddMutation(RefreshEntry entry) {
+    Mutation m = new Mutation(createRow(entry));
+
+    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DataOutputStream dos = new DataOutputStream(baos)) {
+      dos.writeInt(1);
+      entry.getExtent().writeTo(dos);
+      dos.writeUTF(entry.getTserver().getHostPortSession());
+      dos.close();

Review Comment:
   I was closing it before getting the array from the byte array output stream.



##########
server/base/src/main/java/org/apache/accumulo/server/metadata/RefreshesImpl.java:
##########
@@ -0,0 +1,237 @@
+/*
+ * 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
+ *
+ *   https://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.metadata;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static 
org.apache.accumulo.core.metadata.RootTable.ZROOT_TABLET_REFRESHES;
+import static org.apache.accumulo.core.util.LazySingletons.GSON;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.metadata.RootTable;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.core.metadata.schema.ExternalCompactionId;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.RefreshSection;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.hadoop.io.Text;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public class RefreshesImpl implements Ample.Refreshes {
+
+  private static final Logger log = 
LoggerFactory.getLogger(RefreshesImpl.class);
+
+  private final Ample.DataLevel dataLevel;
+  private final ServerContext context;
+
+  public static String getInitialJson() {
+    return toJson(Map.of());
+  }
+
+  // This class is used to serialize and deserialize root tablet metadata 
using GSon. Any changes to
+  // this class must consider persisted data.
+  private static class Data {

Review Comment:
   Fixed in dedaa88



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to