keith-turner commented on a change in pull request #575: Add splits to table at 
time of table creation #573
URL: https://github.com/apache/accumulo/pull/575#discussion_r206295436
 
 

 ##########
 File path: 
server/master/src/main/java/org/apache/accumulo/master/tableOps/CreateInitialSplits.java
 ##########
 @@ -0,0 +1,179 @@
+/*
+ * 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.master.tableOps;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Map;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+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.conf.Property;
+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.data.impl.KeyExtent;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.fate.Repo;
+import org.apache.accumulo.master.Master;
+import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.io.Text;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.data.Stat;
+
+public class CreateInitialSplits extends MasterRepo {
+
+  private static final long serialVersionUID = 1L;
+
+  private TableInfo tableInfo;
+
+  CreateInitialSplits(TableInfo ti) {
+    this.tableInfo = ti;
+  }
+
+  private class SplitEntry {
+    Value dirValue;
+    Value lockValue;
+    Value timeValue;
+    Value firstRow;
+    String lastSplit;
+    boolean first;
+
+    public SplitEntry() {
+      dirValue = null;
+      lockValue = null;
+      timeValue = null;
+      firstRow = null;
+      lastSplit = null;
+      first = true;
+    }
+  };
+
+  @Override
+  public long isReady(long tid, Master environment) throws Exception {
+    return 0;
+  }
+
+  @Override
+  public Repo<Master> call(long tid, Master environment) throws Exception {
+    String splitFile = getSplitFileName();
+
+    // Read table entry and store values for later use
+    SplitEntry splitEntry = new SplitEntry();
+    populateSplitEntry(environment, splitEntry);
+
+    try (BatchWriter bw = 
environment.getConnector().createBatchWriter("accumulo.metadata")) {
+
+      // Read splits from filesystem and write to metadata table.
+      writeSplitsToMetadataTable(environment, splitFile, splitEntry, bw);
+
+      // last row is handled as a special case
+      writeLastRowToMetadataTable(splitEntry, bw);
+    }
+
+    return new FinishCreateTable(tableInfo);
+  }
+
+  private void writeLastRowToMetadataTable(SplitEntry splitEntry, BatchWriter 
bw)
+      throws MutationsRejectedException {
+    Text lastRow = new Text(tableInfo.tableId.toString() + "<");
+    Mutation mut = new Mutation(lastRow);
+    mut.put(new Text("srv"), new Text("dir"), splitEntry.dirValue);
 
 Review comment:
   Really need to use constants here.   In PopulateMetadata it calls 
`MetadataTableUtil.addTablet()`.  If you dig into the source of `addTablet()` 
you can see the constants its uses.   Some of the constants are quirky, let me 
know if you have any questions.  I would be happy to provide examples if needed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to