List of usage examples for java.lang Object notifyAll
@HotSpotIntrinsicCandidate public final native void notifyAll();
From source file:org.cloudgraph.hbase.graph.ParallelSliceSubgraphTask.java
/** * Assembles a given set of edges where the target is a different row, within * this table or another. Since we are assembling a graph, each edge requires * a new row reader. Each edge is a new root in the target table so need a new * row reader for each./* ww w .ja va 2 s . c om*/ * * @param target * the object source to which we link edges * @param prop * the edge property * @param edges * the edges * @param rowReader * the row reader * @param childTableReader * the table reader for the child objects * @param level * the assembly level * @throws IOException */ protected void assembleExternalEdges(PlasmaDataObject target, long targetSequence, PlasmaProperty prop, EdgeReader collection, RowReader rowReader, List<CellValues> resultRows, TableReader childTableReader, int level) throws IOException { for (CellValues childValues : resultRows) { CellValues childResult = null; if (resultRows != null && !resultRows.contains(Arrays.hashCode(childValues.getRowKey()))) continue; // not found in predicate // see if this row is locked during fetch, and wait for it Object rowLock = fetchLocks.get(Arrays.hashCode(childValues.getRowKey())); if (rowLock != null) { synchronized (rowLock) { try { rowLock.wait(); } catch (InterruptedException e) { log.error(e.getMessage(), e); } } } RowReader existingChildRowReader = childTableReader.getRowReader(childValues.getRowKey()); if (existingChildRowReader != null) { // If assembled this row root before, // just link it. The data is already complete. PlasmaDataObject existingChild = (PlasmaDataObject) existingChildRowReader.getRootDataObject(); synchronized (existingChild) { synchronized (target) { link(existingChild, target, prop); } } continue; } // While fetching this node, another thread can fail to find an // existing row reader registered // above and fall through to this fetch, and therefore fetch the // same row, in addition // to attempting to create the same row reader below, causing an // error or warning // The second thread may be arriving at this node from another // property/edge and // therefore need to link from another edge above. fetchLocks.put(Arrays.hashCode(childValues.getRowKey()), new Object()); if (log.isDebugEnabled()) log.debug("fetch external row: " + prop.toString() + " (" + childValues.getRowKey() + ")"); childResult = fetchGraph(childValues.getRowKey(), childTableReader, collection.getBaseType()); if (childResult.containsColumn(rootTableReader.getTableConfig().getDataColumnFamilyNameBytes(), GraphMetaKey.TOMBSTONE.codeAsBytes())) { log.warn("ignoring toubstone result row '" + childValues.getRowKey() + "'"); continue; // ignore toumbstone edge } PlasmaType subType = collection.getSubType(); if (subType == null) subType = collection.getBaseType(); GraphColumnKeyFactory keyFactory = this.getKeyFactory(subType); byte[] uuidQual = keyFactory.createColumnKey(subType, EntityMetaKey.UUID); // need to reconstruct the original graph, so need original UUID byte[] rootUuid = childResult.getColumnValue( Bytes.toBytes(childTableReader.getTableConfig().getDataColumnFamilyName()), uuidQual); if (rootUuid == null) throw new GraphServiceException( "expected column: " + childTableReader.getTableConfig().getDataColumnFamilyName() + ":" + Bytes.toString(uuidQual)); String uuidStr = null; uuidStr = new String(rootUuid, childTableReader.getTableConfig().getCharset()); UUID uuid = UUID.fromString(uuidStr); PlasmaDataObject child = null; synchronized (target) { // create a child object using UUID from external row root child = createChild(source, sourceProperty, uuid, collection.getBaseType()); } RowReader childRowReader = null; synchronized (childTableReader) { // create a row reader for every external edge childRowReader = childTableReader.createRowReader(child, childResult); } synchronized (this.distributedReader) { this.distributedReader.mapRowReader(childValues.getRowKey(), childRowReader); } synchronized (target) { childRowReader.addDataObject(child); } // FIXME: we have the child already why is the sequence needed traversals.add(new Traversal(child, -1, collection, target, prop, childRowReader, true, level + 1)); rowLock = fetchLocks.remove(Arrays.hashCode(childValues.getRowKey())); synchronized (rowLock) { rowLock.notifyAll(); } } }
From source file:org.apache.hadoop.hbase.client.TestFromClientSide.java
@Ignore("Flakey: HBASE-8989") @Test/*from ww w. j a va2s . c o m*/ public void testClientPoolThreadLocal() throws IOException { final byte[] tableName = Bytes.toBytes("testClientPoolThreadLocal"); int poolSize = Integer.MAX_VALUE; int numVersions = 3; Configuration conf = TEST_UTIL.getConfiguration(); conf.set(HConstants.HBASE_CLIENT_IPC_POOL_TYPE, "thread-local"); conf.setInt(HConstants.HBASE_CLIENT_IPC_POOL_SIZE, poolSize); final HTable table = TEST_UTIL.createTable(tableName, new byte[][] { FAMILY }, conf, 3); final long ts = EnvironmentEdgeManager.currentTimeMillis(); final Get get = new Get(ROW); get.addColumn(FAMILY, QUALIFIER); get.setMaxVersions(); for (int versions = 1; versions <= numVersions; versions++) { Put put = new Put(ROW); put.add(FAMILY, QUALIFIER, ts + versions, VALUE); table.put(put); Result result = table.get(get); NavigableMap<Long, byte[]> navigableMap = result.getMap().get(FAMILY).get(QUALIFIER); assertEquals("The number of versions of '" + FAMILY + ":" + QUALIFIER + " did not match " + versions + "; " + put.toString() + ", " + get.toString(), versions, navigableMap.size()); for (Map.Entry<Long, byte[]> entry : navigableMap.entrySet()) { assertTrue("The value at time " + entry.getKey() + " did not match what was put", Bytes.equals(VALUE, entry.getValue())); } } final Object waitLock = new Object(); ExecutorService executorService = Executors.newFixedThreadPool(numVersions); final AtomicReference<AssertionError> error = new AtomicReference<AssertionError>(null); for (int versions = numVersions; versions < numVersions * 2; versions++) { final int versionsCopy = versions; executorService.submit(new Callable<Void>() { @Override public Void call() { try { Put put = new Put(ROW); put.add(FAMILY, QUALIFIER, ts + versionsCopy, VALUE); table.put(put); Result result = table.get(get); NavigableMap<Long, byte[]> navigableMap = result.getMap().get(FAMILY).get(QUALIFIER); assertEquals( "The number of versions of '" + Bytes.toString(FAMILY) + ":" + Bytes.toString(QUALIFIER) + " did not match " + versionsCopy, versionsCopy, navigableMap.size()); for (Map.Entry<Long, byte[]> entry : navigableMap.entrySet()) { assertTrue("The value at time " + entry.getKey() + " did not match what was put", Bytes.equals(VALUE, entry.getValue())); } synchronized (waitLock) { waitLock.wait(); } } catch (Exception e) { } catch (AssertionError e) { // the error happens in a thread, it won't fail the test, // need to pass it to the caller for proper handling. error.set(e); LOG.error(e); } return null; } }); } synchronized (waitLock) { waitLock.notifyAll(); } executorService.shutdownNow(); assertNull(error.get()); }