/**
  * Remove the @Ignore to try out timeout and retry asettings
  *
  * @throws IOException
  */
 @Ignore
 @Test
 public void testTimeoutAndRetries() throws IOException {
   Configuration localConfig = HBaseConfiguration.create(this.conf);
   // This override mocks up our exists/get call to throw a RegionServerStoppedException.
   localConfig.set("hbase.client.connection.impl", RpcTimeoutConnection.class.getName());
   HTable table = new HTable(localConfig, TableName.META_TABLE_NAME);
   Throwable t = null;
   LOG.info("Start");
   try {
     // An exists call turns into a get w/ a flag.
     table.exists(new Get(Bytes.toBytes("abc")));
   } catch (SocketTimeoutException e) {
     // I expect this exception.
     LOG.info("Got expected exception", e);
     t = e;
   } catch (RetriesExhaustedException e) {
     // This is the old, unwanted behavior.  If we get here FAIL!!!
     fail();
   } finally {
     table.close();
   }
   LOG.info("Stop");
   assertTrue(t != null);
 }
Esempio n. 2
0
 protected void verifyRoundRobinDistribution(HTable ht, int expectedRegions) throws IOException {
   MasterServices services = TEST_UTIL.getMiniHBaseCluster().getMaster();
   AssignmentManager am = services.getAssignmentManager();
   Map<HRegionInfo, HServerAddress> regions = ht.getRegionsInfo();
   for (HRegionInfo regionInfo : regions.keySet()) {
     try {
       am.waitForAssignment(regionInfo);
     } catch (InterruptedException e) {
       LOG.info("Interrupted waiting for region to be assigned during " + "create table call", e);
       Thread.currentThread().interrupt();
       return;
     }
   }
   int numRS = ht.getCurrentNrHRS();
   regions = ht.getRegionsInfo();
   Map<HServerAddress, List<HRegionInfo>> server2Regions =
       new HashMap<HServerAddress, List<HRegionInfo>>();
   for (Map.Entry<HRegionInfo, HServerAddress> entry : regions.entrySet()) {
     HServerAddress server = entry.getValue();
     List<HRegionInfo> regs = server2Regions.get(server);
     if (regs == null) {
       regs = new ArrayList<HRegionInfo>();
       server2Regions.put(server, regs);
     }
     regs.add(entry.getKey());
   }
   float average = (float) expectedRegions / numRS;
   int min = (int) Math.floor(average);
   int max = (int) Math.ceil(average);
   for (List<HRegionInfo> regionList : server2Regions.values()) {
     assertTrue(regionList.size() == min || regionList.size() == max);
   }
 }
 /**
  * Test that operation timeout prevails over rpc default timeout and retries, etc.
  *
  * @throws IOException
  */
 @Test
 public void testRocTimeout() throws IOException {
   Configuration localConfig = HBaseConfiguration.create(this.conf);
   // This override mocks up our exists/get call to throw a RegionServerStoppedException.
   localConfig.set("hbase.client.connection.impl", RpcTimeoutConnection.class.getName());
   int pause = 10;
   localConfig.setInt("hbase.client.pause", pause);
   localConfig.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 10);
   // Set the operation timeout to be < the pause.  Expectation is that after first pause, we will
   // fail out of the rpc because the rpc timeout will have been set to the operation tiemout
   // and it has expired.  Otherwise, if this functionality is broke, all retries will be run --
   // all ten of them -- and we'll get the RetriesExhaustedException exception.
   localConfig.setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, pause - 1);
   HTable table = new HTable(localConfig, TableName.META_TABLE_NAME);
   Throwable t = null;
   try {
     // An exists call turns into a get w/ a flag.
     table.exists(new Get(Bytes.toBytes("abc")));
   } catch (SocketTimeoutException e) {
     // I expect this exception.
     LOG.info("Got expected exception", e);
     t = e;
   } catch (RetriesExhaustedException e) {
     // This is the old, unwanted behavior.  If we get here FAIL!!!
     fail();
   } finally {
     table.close();
   }
   assertTrue(t != null);
 }
Esempio n. 4
0
  private void testTruncateTable(final TableName tableName, boolean preserveSplits)
      throws IOException {
    byte[][] splitKeys = new byte[2][];
    splitKeys[0] = Bytes.toBytes(4);
    splitKeys[1] = Bytes.toBytes(8);

    // Create & Fill the table
    HTable table = TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY, splitKeys);
    try {
      TEST_UTIL.loadNumericRows(table, HConstants.CATALOG_FAMILY, 0, 10);
      assertEquals(10, TEST_UTIL.countRows(table));
    } finally {
      table.close();
    }
    assertEquals(3, TEST_UTIL.getHBaseCluster().getRegions(tableName).size());

    // Truncate & Verify
    this.admin.disableTable(tableName);
    this.admin.truncateTable(tableName, preserveSplits);
    table = new HTable(TEST_UTIL.getConfiguration(), tableName);
    try {
      assertEquals(0, TEST_UTIL.countRows(table));
    } finally {
      table.close();
    }
    if (preserveSplits) {
      assertEquals(3, TEST_UTIL.getHBaseCluster().getRegions(tableName).size());
    } else {
      assertEquals(1, TEST_UTIL.getHBaseCluster().getRegions(tableName).size());
    }
  }
Esempio n. 5
0
  @Test
  public void insert_rowkey_prefix_date() throws IOException {

    System.out.println(errorTable);
    errorTable.setAutoFlushTo(false);
    List<Put> puts = new ArrayList<Put>();
    long t1 = System.currentTimeMillis();
    for (int i = 0; i < 10000000; i++) {
      String uuid = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 8);
      Put put = new Put(Bytes.toBytes("20150705" + "_" + uuid));
      put.add(
          fBytes,
          Bytes.toBytes("stacktrace"),
          Bytes.toBytes("java.io.IOException:file not found" + UUID.randomUUID().toString()));
      //            puts.add(put);
      errorTable.put(put);
      if (i % 10000 == 0) {
        errorTable.flushCommits();
      }
    }
    errorTable.flushCommits();
    long t2 = System.currentTimeMillis();
    System.out.println("count=" + puts.size() + ",t2-t1=" + (t2 - t1));
    //        errorTable.close();
  }
Esempio n. 6
0
  /**
   * @param conn The HBase connection.
   * @param conf The HBase configuration
   * @param perRegionServerBufferQueueSize determines the max number of the buffered Put ops for
   *     each region server before dropping the request.
   */
  public HTableMultiplexer(
      Connection conn, Configuration conf, int perRegionServerBufferQueueSize) {
    this.conn = (ClusterConnection) conn;
    this.pool = HTable.getDefaultExecutor(conf);
    // how many times we could try in total, one more than retry number
    this.maxAttempts =
        conf.getInt(
                HConstants.HBASE_CLIENT_RETRIES_NUMBER,
                HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER)
            + 1;
    this.perRegionServerBufferQueueSize = perRegionServerBufferQueueSize;
    this.maxKeyValueSize = HTable.getMaxKeyValueSize(conf);
    this.flushPeriod = conf.getLong(TABLE_MULTIPLEXER_FLUSH_PERIOD_MS, 100);
    int initThreads = conf.getInt(TABLE_MULTIPLEXER_INIT_THREADS, 10);
    this.executor =
        Executors.newScheduledThreadPool(
            initThreads,
            new ThreadFactoryBuilder()
                .setDaemon(true)
                .setNameFormat("HTableFlushWorker-%d")
                .build());

    this.workerConf = HBaseConfiguration.create(conf);
    // We do not do the retry because we need to reassign puts to different queues if regions are
    // moved.
    this.workerConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 0);
  }
Esempio n. 7
0
  /*
   * (non-Javadoc)
   *
   * @see com.hazelcast.core.MapStore#storeAll(java.util.Map)
   */
  @Override
  public void storeAll(Map<String, String> pairs) {
    HTable table = null;
    try {
      List<Put> puts = new ArrayList<Put>(pairs.size());
      for (Map.Entry<String, String> pair : pairs.entrySet()) {
        try {
          byte[] rowId =
              prefixDate ? IdUtil.bucketizeId(pair.getKey()) : Bytes.toBytes(pair.getKey());
          Put p = new Put(rowId);
          if (outputFormatType == StoreFormatType.SMILE) {
            p.add(family, qualifier, jsonSmileConverter.convertToSmile(pair.getValue()));
          } else {
            p.add(family, qualifier, Bytes.toBytes(pair.getValue()));
          }
          puts.add(p);
        } catch (NumberFormatException nfe) {
          LOG.error("Encountered bad key: " + pair.getKey(), nfe);
        }
      }

      table = (HTable) pool.getTable(tableName);
      table.setAutoFlush(false);
      table.put(puts);
      table.flushCommits();
    } catch (IOException e) {
      LOG.error("Error during puts", e);
    } finally {
      if (table != null) {
        pool.putTable(table);
      }
    }
  }
  public int run(String[] args) throws Exception {
    Configuration argConf = getConf();

    // JobConf conf = new JobConf(diffdb.class);
    Configuration config = HBaseConfiguration.create();
    HBaseAdmin hbAdmin = new HBaseAdmin(config);
    dbutil db_util = new dbutil(config);

    HTable runTable = new HTable(config, "gestore_runs");
    Get runGet = new Get(argConf.get("id").getBytes());
    Result pipeline = runTable.get(runGet);

    NavigableMap<byte[], byte[]> pipeMap = pipeline.getFamilyMap("d".getBytes());

    Map.Entry<byte[], byte[]> results = pipeMap.pollFirstEntry();

    HashMap<String, HashMap<String, String>> resultMap =
        new HashMap<String, HashMap<String, String>>();

    while (results != null) {
      String resultKey = new String(results.getKey());
      String resultValue = new String(results.getValue());
      String field = "type";
      HashMap<String, String> tempMap = new HashMap<String, String>();
      String entry = resultKey;

      if (resultKey.endsWith("_db_timestamp")) {
        field = "db_timestamp";
        entry = resultKey.substring(0, resultKey.lastIndexOf("_db_timestamp"));
      } else if (resultKey.endsWith("_filename")) {
        field = "filename";
        entry = resultKey.substring(0, resultKey.lastIndexOf("_filename"));
      } else if (resultKey.endsWith("_regex")) {
        field = "regex";
        entry = resultKey.substring(0, resultKey.lastIndexOf("_regex"));
      }

      if (resultMap.containsKey(entry)) {
        tempMap = resultMap.get(entry);
      }

      tempMap.put(field, resultValue);
      resultMap.put(entry, tempMap);

      // System.out.println("Key: " + resultKey + " Value: " + resultValue);
      results = pipeMap.pollFirstEntry();
    }

    for (String key : resultMap.keySet()) {
      System.out.println("File ID: " + key);
      for (String subKey : resultMap.get(key).keySet()) {
        // System.out.println("\t " + subKey + "\t\t" + resultMap.get(key).get(subKey));
        System.out.format("  %1$-20s  %2$s\n", subKey, resultMap.get(key).get(subKey));
      }
    }

    return 0;
  }
Esempio n. 9
0
 /**
  * Test read only tables
  *
  * @throws Exception
  */
 @Test
 public void testReadOnlyTable() throws Exception {
   byte[] name = Bytes.toBytes("testReadOnlyTable");
   HTable table = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY);
   byte[] value = Bytes.toBytes("somedata");
   // This used to use an empty row... That must have been a bug
   Put put = new Put(value);
   put.add(HConstants.CATALOG_FAMILY, HConstants.CATALOG_FAMILY, value);
   table.put(put);
 }
Esempio n. 10
0
 /**
  * Returns the HNodePath for this node.
  *
  * @param factory
  * @return the HNodePath for this node.
  */
 public HNodePath getHNodePath(RepFactory factory) {
   HNodePath p1 = new HNodePath(this);
   // get the table that it belongs to
   HTable t = factory.getHTable(hTableId);
   HNode parentNode = t.getParentHNode();
   if (parentNode != null) {
     HNodePath p2 = parentNode.getHNodePath(factory);
     p1 = HNodePath.concatenate(p2, p1);
   }
   return p1;
 }
Esempio n. 11
0
  @Override
  public void tweet(User user, String tweetText) throws IOException {
    final long epoch = System.currentTimeMillis();
    final long tranposeEpoch = Long.MAX_VALUE - epoch;
    final byte[] epochBytes = Bytes.toBytes(epoch);

    final byte[] tweetBytes = Bytes.toBytes(tweetText);
    byte[] nameBytes = Bytes.toBytes(user.getName());

    /** put tweet into tweets */
    Put tweetRowPut = new Put(generateTweetId(user));

    tweetRowPut.add(_DEFAULT, _NAME, nameBytes);
    tweetRowPut.add(_DEFAULT, _MAIL, Bytes.toBytes(user.getEmail()));
    tweetRowPut.add(_DEFAULT, _TWEET, tweetBytes);
    tweetRowPut.add(_DEFAULT, _TIME, epochBytes);

    tweetsTable.put(tweetRowPut);

    /** put tweets for followers */
    Scan followerScan = new Scan();
    followerScan.setStartRow(Bytes.toBytes(user.getUserId() + "-"));
    followerScan.setStopRow(Bytes.toBytes((user.getUserId() + 1) + "-"));

    ResultScanner followerRS = followersTable.getScanner(followerScan);

    /** put users on tweet to her own tweetline */
    Put put =
        new Put(Bytes.toBytes(user.getUserId() + "-" + tranposeEpoch + "-" + user.getUserId()));
    put.add(_DEFAULT, _NAME, nameBytes);
    put.add(_DEFAULT, _TWEET, tweetBytes);
    put.add(_DEFAULT, _TIME, epochBytes);

    List<Row> puts = new ArrayList<Row>();
    puts.add(put);
    for (Result result : followerRS) {

      Long followerid = Bytes.toLong(result.getColumnLatest(_DEFAULT, _USERID).getValue());

      put = new Put(Bytes.toBytes(followerid + "-" + tranposeEpoch + "-" + user.getUserId()));
      put.add(_DEFAULT, _NAME, nameBytes);
      put.add(_DEFAULT, _TWEET, tweetBytes);
      put.add(_DEFAULT, _TIME, epochBytes);

      puts.add(put);
    }
    followerRS.close();
    try {
      tweetlineTable.batch(puts);
    } catch (InterruptedException e) {
      e.printStackTrace(); // @TODO log and handle properly.
    }
  }
Esempio n. 12
0
 @Test
 public void testGetTableDescriptor() throws IOException {
   HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
   HColumnDescriptor fam2 = new HColumnDescriptor("fam2");
   HColumnDescriptor fam3 = new HColumnDescriptor("fam3");
   HTableDescriptor htd = new HTableDescriptor("myTestTable");
   htd.addFamily(fam1);
   htd.addFamily(fam2);
   htd.addFamily(fam3);
   this.admin.createTable(htd);
   HTable table = new HTable(TEST_UTIL.getConfiguration(), "myTestTable");
   HTableDescriptor confirmedHtd = table.getTableDescriptor();
   assertEquals(htd.compareTo(confirmedHtd), 0);
 }
Esempio n. 13
0
 public static void SeedData(HBaseConfiguration conf) throws IOException {
   HTable table = new HTable(conf, "people");
   Put put = new Put(Bytes.toBytes("doe-john-m-12345"));
   put.add(Bytes.toBytes("personal"), Bytes.toBytes("givenName"), Bytes.toBytes("John"));
   put.add(Bytes.toBytes("personal"), Bytes.toBytes("mi"), Bytes.toBytes("M"));
   put.add(Bytes.toBytes("personal"), Bytes.toBytes("surame"), Bytes.toBytes("Doe"));
   put.add(
       Bytes.toBytes("contactinfo"),
       Bytes.toBytes("email"),
       Bytes.toBytes("*****@*****.**"));
   table.put(put);
   table.flushCommits();
   table.close();
 }
Esempio n. 14
0
  @Test
  public void testMetaScanner() throws Exception {
    LOG.info("Starting testMetaScanner");

    setUp();
    final TableName TABLENAME = TableName.valueOf("testMetaScanner");
    final byte[] FAMILY = Bytes.toBytes("family");
    TEST_UTIL.createTable(TABLENAME, FAMILY);
    Configuration conf = TEST_UTIL.getConfiguration();
    HTable table = (HTable) connection.getTable(TABLENAME);
    TEST_UTIL.createMultiRegions(
        conf,
        table,
        FAMILY,
        new byte[][] {
          HConstants.EMPTY_START_ROW, Bytes.toBytes("region_a"), Bytes.toBytes("region_b")
        });
    // Make sure all the regions are deployed
    TEST_UTIL.countRows(table);

    MetaScanner.MetaScannerVisitor visitor = mock(MetaScanner.MetaScannerVisitor.class);
    doReturn(true).when(visitor).processRow((Result) anyObject());

    // Scanning the entire table should give us three rows
    MetaScanner.metaScan(connection, visitor, TABLENAME);
    verify(visitor, times(3)).processRow((Result) anyObject());

    // Scanning the table with a specified empty start row should also
    // give us three hbase:meta rows
    reset(visitor);
    doReturn(true).when(visitor).processRow((Result) anyObject());
    MetaScanner.metaScan(connection, visitor, TABLENAME, HConstants.EMPTY_BYTE_ARRAY, 1000);
    verify(visitor, times(3)).processRow((Result) anyObject());

    // Scanning the table starting in the middle should give us two rows:
    // region_a and region_b
    reset(visitor);
    doReturn(true).when(visitor).processRow((Result) anyObject());
    MetaScanner.metaScan(connection, visitor, TABLENAME, Bytes.toBytes("region_ac"), 1000);
    verify(visitor, times(2)).processRow((Result) anyObject());

    // Scanning with a limit of 1 should only give us one row
    reset(visitor);
    doReturn(true).when(visitor).processRow((Result) anyObject());
    MetaScanner.metaScan(connection, visitor, TABLENAME, Bytes.toBytes("region_ac"), 1);
    verify(visitor, times(1)).processRow((Result) anyObject());
    table.close();
  }
Esempio n. 15
0
  /**
   * The put request will be buffered by its corresponding buffer queue. And the put request will be
   * retried before dropping the request. Return false if the queue is already full.
   *
   * @return true if the request can be accepted by its corresponding buffer queue.
   */
  public boolean put(final TableName tableName, final Put put, int maxAttempts) {
    if (maxAttempts <= 0) {
      return false;
    }

    try {
      HTable.validatePut(put, maxKeyValueSize);
      // Allow mocking to get at the connection, but don't expose the connection to users.
      ClusterConnection conn = (ClusterConnection) getConnection();
      // AsyncProcess in the FlushWorker should take care of refreshing the location cache
      // as necessary. We shouldn't have to do that here.
      HRegionLocation loc = conn.getRegionLocation(tableName, put.getRow(), false);
      if (loc != null) {
        // Add the put pair into its corresponding queue.
        LinkedBlockingQueue<PutStatus> queue = getQueue(loc);

        // Generate a MultiPutStatus object and offer it into the queue
        PutStatus s = new PutStatus(loc.getRegionInfo(), put, maxAttempts);

        return queue.offer(s);
      }
    } catch (IOException e) {
      LOG.debug("Cannot process the put " + put, e);
    }
    return false;
  }
Esempio n. 16
0
  @Override
  public Set<Element> get(Object key) {
    Get get = new Get(ByteArraySerializer.fromObject(key));
    Result result;
    try {
      result = backingTable.get(get);
    } catch (IOException e) {
      LOG.severe("Cannot get from backing table");
      e.printStackTrace();
      return null;
    }

    NavigableMap<byte[], byte[]> map = result.getFamilyMap(Bytes.toBytes(VALUES));
    if (null == map) return null;

    HashSet<Element> elementHashSet = new HashSet<Element>();

    for (byte[] byteArray : map.keySet()) {

      if (indexClass.equals(HVertex.class) || indexClass.equals(Vertex.class)) {
        HVertex hVertex = new HVertex(hGraph);
        hVertex.setId(byteArray);
        elementHashSet.add(hVertex);
      } else {
        final HEdge hEdge = new HEdge(hGraph);
        hEdge.setId(byteArray);
        elementHashSet.add(hEdge);
      }
    }

    return elementHashSet;
  }
Esempio n. 17
0
 public void putBatch(Optional<List<Request>> putRequests, boolean optimize) {
   if (!valid) {
     Logger.error("CANNOT PUT! NO VALID CONNECTION");
     return;
   }
   List<Put> puts = new ArrayList<>();
   if (putRequests.isPresent() && !putRequests.get().isEmpty()) {
     String tableName = putRequests.get().get(0).table;
     putRequests
         .get()
         .forEach(
             pr ->
                 pr.getPut()
                     .ifPresent(
                         p -> {
                           if (optimize) {
                             p.setDurability(Durability.SKIP_WAL);
                           }
                           puts.add(p);
                         }));
     try {
       final Table table = connection.getTable(TableName.valueOf(tableName));
       if (optimize && table instanceof HTable) {
         ((HTable) table).setAutoFlush(false, true);
       }
       table.put(puts);
       table.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
Esempio n. 18
0
 public HTable addNestedTable(String tableName, Worksheet worksheet, RepFactory factory) {
   nestedTable = factory.createHTable(tableName);
   // mariam
   nestedTable.setParentHNode(this);
   worksheet.addNestedTableToDataTable(this, factory);
   return nestedTable;
 }
Esempio n. 19
0
  @After
  public void close() throws IOException {
    if (errorTable != null) {

      errorTable.close();
    }
  }
Esempio n. 20
0
 @Test
 public void testRegionServerStoppedOnScannerOpen() throws IOException {
   this.conf.set(
       "hbase.client.connection.impl", RegionServerStoppedOnScannerOpenConnection.class.getName());
   // Go against meta else we will try to find first region for the table on construction which
   // means we'll have to do a bunch more mocking.  Tests that go against meta only should be
   // good for a bit of testing.
   HTable table = new HTable(this.conf, TableName.META_TABLE_NAME);
   ResultScanner scanner = table.getScanner(HConstants.CATALOG_FAMILY);
   try {
     Result result = null;
     while ((result = scanner.next()) != null) {
       LOG.info(result);
     }
   } finally {
     scanner.close();
     table.close();
   }
 }
Esempio n. 21
0
 public void removeSingleElement(Object key, Element value) {
   final Delete delete = new Delete(ByteArraySerializer.fromObject(key));
   delete.deleteColumns(Bytes.toBytes(VALUES), (byte[]) value.getId());
   try {
     backingTable.delete(delete);
   } catch (IOException e) {
     LOG.severe("Cannot delete from backing table");
     e.printStackTrace();
   }
 }
Esempio n. 22
0
 @Override
 public Set<Element> remove(Object key) {
   Delete del = new Delete(ByteArraySerializer.fromObject(key));
   try {
     backingTable.delete(del);
   } catch (IOException e) {
     LOG.severe("Error while deleting from table");
     e.printStackTrace();
   }
   return null;
 }
Esempio n. 23
0
  public JSONArray getJSONArrayRepresentation(RepFactory f) throws JSONException {
    JSONArray arr = new JSONArray();
    Stack<HNode> st = new Stack<HNode>();
    st.push(this);
    HTable t = f.getHTable(hTableId);
    HNode parentNode = t.getParentHNode();
    while (parentNode != null) {
      st.push(parentNode);
      t = f.getHTable(parentNode.getHTableId());
      parentNode = t.getParentHNode();
    }

    while (!st.isEmpty()) {
      HNode node = st.pop();
      JSONObject obj = new JSONObject();
      obj.put("columnName", node.getColumnName());
      arr.put(obj);
    }
    return arr;
  }
Esempio n. 24
0
  public static void scanNum(String tableStr) {
    try {
      Configuration conf = HBaseConfiguration.create();
      Scan scan = new Scan();
      scan.setCaching(5000);
      Filter f = new FirstKeyOnlyFilter();
      scan.setFilter(f);

      HTable htable = new HTable(conf, Bytes.toBytes(tableStr));
      ResultScanner scanner = htable.getScanner(scan);
      int count = 0;
      for (Result scannerRst : scanner) {
        count++;
      }
      System.out.println(tableStr + ":" + count);
      scanner.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 25
0
 @Override
 public void prettyPrint(String prefix, PrintWriter pw, RepFactory factory) {
   pw.print(prefix + "- ");
   pw.print(columnName);
   pw.print("/" + id);
   if (nestedTable != null) {
     pw.println(": ");
     nestedTable.prettyPrint(prefix + "    ", pw, factory);
   } else {
     pw.println();
   }
 }
Esempio n. 26
0
  /**
   * Deletes the specified table with all its columns. ATTENTION: Invoking this method will delete
   * the table if it exists and therefore causes data loss.
   */
  @Override
  public void clearStorage() throws StorageException {
    HBaseAdmin adm = getAdminInterface();

    try { // first of all, check if table exists, if not - we are done
      if (!adm.tableExists(tableName)) {
        logger.debug("clearStorage() called before table {} was created, skipping.", tableName);
        return;
      }
    } catch (IOException e) {
      throw new TemporaryStorageException(e);
    }

    HTable table = null;

    try {
      table = new HTable(hconf, tableName);

      Scan scan = new Scan();
      scan.setBatch(100);
      scan.setCacheBlocks(false);
      scan.setCaching(2000);

      ResultScanner scanner = null;

      try {
        scanner = table.getScanner(scan);

        for (Result res : scanner) {
          table.delete(new Delete(res.getRow()));
        }
      } finally {
        IOUtils.closeQuietly(scanner);
      }
    } catch (IOException e) {
      throw new TemporaryStorageException(e);
    } finally {
      IOUtils.closeQuietly(table);
    }
  }
Esempio n. 27
0
 @SuppressWarnings("deprecation")
 protected void verifyRoundRobinDistribution(HTable ht, int expectedRegions) throws IOException {
   int numRS = ht.getConnection().getCurrentNrHRS();
   Map<HRegionInfo, ServerName> regions = ht.getRegionLocations();
   Map<ServerName, List<HRegionInfo>> server2Regions =
       new HashMap<ServerName, List<HRegionInfo>>();
   for (Map.Entry<HRegionInfo, ServerName> entry : regions.entrySet()) {
     ServerName server = entry.getValue();
     List<HRegionInfo> regs = server2Regions.get(server);
     if (regs == null) {
       regs = new ArrayList<HRegionInfo>();
       server2Regions.put(server, regs);
     }
     regs.add(entry.getKey());
   }
   float average = (float) expectedRegions / numRS;
   int min = (int) Math.floor(average);
   int max = (int) Math.ceil(average);
   for (List<HRegionInfo> regionList : server2Regions.values()) {
     assertTrue(regionList.size() == min || regionList.size() == max);
   }
 }
Esempio n. 28
0
  @Test
  public void testDisableAndEnableTable() throws IOException {
    final byte[] row = Bytes.toBytes("row");
    final byte[] qualifier = Bytes.toBytes("qualifier");
    final byte[] value = Bytes.toBytes("value");
    final byte[] table = Bytes.toBytes("testDisableAndEnableTable");
    HTable ht = TEST_UTIL.createTable(table, HConstants.CATALOG_FAMILY);
    Put put = new Put(row);
    put.add(HConstants.CATALOG_FAMILY, qualifier, value);
    ht.put(put);
    Get get = new Get(row);
    get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
    ht.get(get);

    this.admin.disableTable(table);

    // Test that table is disabled
    get = new Get(row);
    get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
    boolean ok = false;
    try {
      ht.get(get);
    } catch (NotServingRegionException e) {
      ok = true;
    } catch (RetriesExhaustedException e) {
      ok = true;
    }
    assertTrue(ok);
    this.admin.enableTable(table);

    // Test that table is enabled
    try {
      ht.get(get);
    } catch (RetriesExhaustedException e) {
      ok = false;
    }
    assertTrue(ok);
  }
Esempio n. 29
0
 @Override
 public Set<Element> put(Object key, Set<Element> value) {
   Put put = new Put(ByteArraySerializer.fromObject(key));
   for (Element val : value)
     put.add(Bytes.toBytes(VALUES), (byte[]) val.getId(), (byte[]) val.getId());
   try {
     backingTable.put(put);
   } catch (IOException e) {
     LOG.severe("Cannot put into backing table");
     e.printStackTrace();
     return null;
   }
   return value;
 }
Esempio n. 30
0
  /**
   * Test retain assignment on enableTable.
   *
   * @throws IOException
   */
  @Test(timeout = 300000)
  public void testEnableTableRetainAssignment() throws IOException {
    final TableName tableName = TableName.valueOf("testEnableTableAssignment");
    byte[][] splitKeys = {
      new byte[] {1, 1, 1},
      new byte[] {2, 2, 2},
      new byte[] {3, 3, 3},
      new byte[] {4, 4, 4},
      new byte[] {5, 5, 5},
      new byte[] {6, 6, 6},
      new byte[] {7, 7, 7},
      new byte[] {8, 8, 8},
      new byte[] {9, 9, 9}
    };
    int expectedRegions = splitKeys.length + 1;
    HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
    admin.createTable(desc, splitKeys);
    HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
    Map<HRegionInfo, ServerName> regions = ht.getRegionLocations();
    assertEquals(
        "Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(),
        expectedRegions,
        regions.size());
    // Disable table.
    admin.disableTable(tableName);
    // Enable table, use retain assignment to assign regions.
    admin.enableTable(tableName);
    Map<HRegionInfo, ServerName> regions2 = ht.getRegionLocations();

    // Check the assignment.
    assertEquals(regions.size(), regions2.size());
    for (Map.Entry<HRegionInfo, ServerName> entry : regions.entrySet()) {
      assertEquals(regions2.get(entry.getKey()), entry.getValue());
    }
  }