99import java .text .DateFormat ;
1010import java .util .ArrayList ;
1111import java .util .Collection ;
12- import java .util .Collections ;
1312import java .util .Date ;
1413import java .util .HashMap ;
1514import java .util .HashSet ;
1615import java .util .Iterator ;
1716import java .util .List ;
1817import java .util .Map ;
1918import java .util .Map .Entry ;
19+ import java .util .Properties ;
2020import java .util .Set ;
2121import java .util .StringTokenizer ;
2222import java .util .UUID ;
4040import org .apache .accumulo .core .clientImpl .ClientConfConverter ;
4141import org .apache .accumulo .core .clientImpl .ClientContext ;
4242import org .apache .accumulo .core .clientImpl .ClientInfo ;
43+ import org .apache .accumulo .core .clientImpl .TabletLocator ;
4344import org .apache .accumulo .core .data .Key ;
4445import org .apache .accumulo .core .data .PartialKey ;
4546import org .apache .accumulo .core .data .Range ;
8283
8384import datawave .accumulo .inmemory .InMemoryAccumuloClient ;
8485import datawave .accumulo .inmemory .InMemoryInstance ;
86+ import datawave .accumulo .inmemory .impl .InMemoryTabletLocator ;
8587import datawave .common .util .ArgumentChecker ;
8688import datawave .ingest .data .config .ingest .AccumuloHelper ;
8789import datawave .mr .bulk .split .DefaultLocationStrategy ;
@@ -1045,10 +1047,27 @@ protected static LocationStrategy getLocationStrategy(Configuration conf) {
10451047 return new DefaultLocationStrategy ();
10461048 }
10471049
1048- public List <Range > binRanges (ClientContext context , List <Range > ranges , Map <String ,Map <KeyExtent ,List <Range >>> binnedRanges )
1049- throws AccumuloException , AccumuloSecurityException , TableNotFoundException {
1050- binnedRanges .put ("" , Collections .singletonMap (new KeyExtent (TableId .of ("" ), null , null ), ranges ));
1051- return Collections .emptyList ();
1050+ /**
1051+ * Initializes an Accumulo {@link TabletLocator} based on the configuration.
1052+ *
1053+ * @param conf
1054+ * the Hadoop configuration object
1055+ * @return an accumulo tablet locator
1056+ * @throws TableNotFoundException
1057+ * if the table name set on the configuration doesn't exist
1058+ * @throws IOException
1059+ * if the input format is unable to read the password file from the FileSystem
1060+ */
1061+ protected static TabletLocator getTabletLocator (Configuration conf ) throws TableNotFoundException , IOException {
1062+ if (conf .getBoolean (MOCK , false ))
1063+ return new InMemoryTabletLocator ();
1064+ String tableName = getTablename (conf );
1065+ Properties props = Accumulo .newClientProperties ().to (conf .get (INSTANCE_NAME ), conf .get (ZOOKEEPERS ))
1066+ .as (getUsername (conf ), new PasswordToken (getPassword (conf ))).build ();
1067+ ClientInfo info = ClientInfo .from (props );
1068+ ClientContext context = new ClientContext (SingletonManager .getClientReservation (), info , ClientConfConverter .toAccumuloConf (info .getProperties ()),
1069+ Threads .UEH );
1070+ return TabletLocator .getLocator (context , context .getTableId (tableName ));
10521071 }
10531072
10541073 /**
@@ -1071,7 +1090,7 @@ public List<InputSplit> getSplits(JobContext job) throws IOException {
10711090
10721091 // get the metadata information for these ranges
10731092 Map <String ,Map <KeyExtent ,List <Range >>> binnedRanges = new HashMap <>();
1074-
1093+ TabletLocator tl ;
10751094 try {
10761095 if (isOfflineScan (job .getConfiguration ())) {
10771096 binnedRanges = binOfflineTable (job , tableName , ranges );
@@ -1083,10 +1102,13 @@ public List<InputSplit> getSplits(JobContext job) throws IOException {
10831102 } else {
10841103 try (AccumuloClient client = getClient (job .getConfiguration ())) {
10851104 TableId tableId = null ;
1105+ tl = getTabletLocator (job .getConfiguration ());
1106+ // its possible that the cache could contain complete, but old information about a tables tablets... so clear it
1107+ tl .invalidateCache ();
10861108 ClientInfo info = ClientInfo .from (cbHelper .newClientProperties ());
10871109 ClientContext context = new ClientContext (SingletonManager .getClientReservation (), info ,
10881110 ClientConfConverter .toAccumuloConf (info .getProperties ()), Threads .UEH );
1089- while (!binRanges (context , ranges , binnedRanges ).isEmpty ()) {
1111+ while (!tl . binRanges (context , ranges , binnedRanges ).isEmpty ()) {
10901112 if (!(client instanceof InMemoryAccumuloClient )) {
10911113 if (tableId == null )
10921114 tableId = context .getTableId (tableName );
@@ -1098,6 +1120,7 @@ public List<InputSplit> getSplits(JobContext job) throws IOException {
10981120 binnedRanges .clear ();
10991121 log .warn ("Unable to locate bins for specified ranges. Retrying." );
11001122 TimeUnit .MILLISECONDS .sleep (ThreadLocalRandom .current ().nextInt (100 , 200 ));
1123+ tl .invalidateCache ();
11011124 }
11021125
11031126 clipRanges (binnedRanges );
@@ -1143,9 +1166,13 @@ public List<InputSplit> getSplits(JobContext job) throws IOException {
11431166 log .info ("There are approximately {} values " , map .size ());
11441167
11451168 for (RangeSplit split : map .keySet ()) {
1146-
1169+ // Iterable<List<Range>> rangeIter = splitter.partition(map.get(split));
1170+ // for (List<Range> rangeList : rangeIter) {
1171+ // RangeSplit newSplit = (RangeSplit) split.clone();
1172+ // newSplit.addRanges(rangeList);
11471173 split .addRanges (map .get (split ));
11481174 splits .add (split );
1175+ // }
11491176
11501177 }
11511178
0 commit comments