Search in sources :

Example 11 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class HdfsZooInstance method getMasterLocations.

@Override
public List<String> getMasterLocations() {
    String masterLocPath = ZooUtil.getRoot(this) + Constants.ZMASTER_LOCK;
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Looking up master location in zoocache.", Thread.currentThread().getId());
        timer = new OpTimer().start();
    }
    byte[] loc = ZooLock.getLockData(zooCache, masterLocPath, null);
    if (timer != null) {
        timer.stop();
        log.trace("tid={} Found master at {} in {}", Thread.currentThread().getId(), (loc == null ? "null" : new String(loc, UTF_8)), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
    }
    if (loc == null) {
        return Collections.emptyList();
    }
    return Collections.singletonList(new String(loc, UTF_8));
}
Also used : OpTimer(org.apache.accumulo.core.util.OpTimer)

Example 12 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class HdfsZooInstance method getRootTabletLocation.

@Override
public String getRootTabletLocation() {
    String zRootLocPath = ZooUtil.getRoot(this) + RootTable.ZROOT_TABLET_LOCATION;
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Looking up root tablet location in zoocache.", Thread.currentThread().getId());
        timer = new OpTimer().start();
    }
    byte[] loc = zooCache.get(zRootLocPath);
    if (timer != null) {
        timer.stop();
        log.trace("tid={} Found root tablet at {} in {}", Thread.currentThread().getId(), (loc == null ? "null" : new String(loc, UTF_8)), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
    }
    if (loc == null) {
        return null;
    }
    return new String(loc, UTF_8).split("\\|")[0];
}
Also used : OpTimer(org.apache.accumulo.core.util.OpTimer)

Example 13 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class NativeMapStressTest method testLotsOfGetsAndScans.

private static void testLotsOfGetsAndScans() {
    ArrayList<Thread> threads = new ArrayList<>();
    final int numThreads = 8;
    final int totalGets = 100000000;
    final int mapSizePerThread = (int) (4000000 / (double) numThreads);
    final int getsPerThread = (int) (totalGets / (double) numThreads);
    for (int tCount = 0; tCount < numThreads; tCount++) {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                NativeMap nm = new NativeMap();
                Random r = new Random();
                OpTimer timer = null;
                AtomicLong nextOpid = new AtomicLong();
                if (log.isInfoEnabled()) {
                    log.info("tid={} oid={} Creating map of size {}", Thread.currentThread().getId(), nextOpid.get(), mapSizePerThread);
                    timer = new OpTimer().start();
                }
                for (int i = 0; i < mapSizePerThread; i++) {
                    String row = String.format("r%08d", i);
                    String val = row + "v";
                    put(nm, row, val, i);
                }
                if (timer != null) {
                    // stop and log created elapsed time
                    timer.stop();
                    log.info("tid={} oid={} Created map of size {} in {}", Thread.currentThread().getId(), nextOpid.getAndIncrement(), nm.size(), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
                    // start timer for gets
                    log.info("tid={} oid={} Doing {} gets()", Thread.currentThread().getId(), nextOpid.get(), getsPerThread);
                    timer.reset().start();
                }
                for (int i = 0; i < getsPerThread; i++) {
                    String row = String.format("r%08d", r.nextInt(mapSizePerThread));
                    String val = row + "v";
                    Value value = nm.get(new Key(new Text(row)));
                    if (value == null || !value.toString().equals(val)) {
                        log.error("nm.get({}) failed", row);
                    }
                }
                if (timer != null) {
                    // stop and log created elapsed time
                    timer.stop();
                    log.info("tid={} oid={} Finished {} gets in {}", Thread.currentThread().getId(), nextOpid.getAndIncrement(), getsPerThread, String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
                    // start timer for random iterations
                    log.info("tid={} oid={} Doing {} random iterations", Thread.currentThread().getId(), nextOpid.get(), getsPerThread);
                    timer.reset().start();
                }
                int scanned = 0;
                for (int i = 0; i < getsPerThread; i++) {
                    int startRow = r.nextInt(mapSizePerThread);
                    String row = String.format("r%08d", startRow);
                    Iterator<Entry<Key, Value>> iter = nm.iterator(new Key(new Text(row)));
                    int count = 0;
                    while (iter.hasNext() && count < 10) {
                        String row2 = String.format("r%08d", startRow + count);
                        String val2 = row2 + "v";
                        Entry<Key, Value> entry = iter.next();
                        if (!entry.getValue().toString().equals(val2) || !entry.getKey().equals(new Key(new Text(row2)))) {
                            log.error("nm.iter({}) failed row = {} count = {} row2 = {} val2 = {}", row2, row, count, row, val2);
                        }
                        count++;
                    }
                    scanned += count;
                }
                if (timer != null) {
                    // stop and log created elapsed time
                    timer.stop();
                    log.info("tid={} oid={} Finished {}  random iterations (scanned = {}) in {}", Thread.currentThread().getId(), nextOpid.getAndIncrement(), getsPerThread, scanned, String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
                }
                nm.delete();
            }
        };
        Thread t = new Thread(r);
        t.start();
        threads.add(t);
    }
    for (Thread thread : threads) {
        try {
            thread.join();
        } catch (InterruptedException e) {
            log.error("Could not join thread '{}'.", thread.getName(), e);
            throw new RuntimeException(e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) AtomicLong(java.util.concurrent.atomic.AtomicLong) Entry(java.util.Map.Entry) Random(java.util.Random) OpTimer(org.apache.accumulo.core.util.OpTimer) Value(org.apache.accumulo.core.data.Value) NativeMap(org.apache.accumulo.tserver.NativeMap) Key(org.apache.accumulo.core.data.Key)

Example 14 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class MetadataLocationObtainer method lookupTablet.

@Override
public TabletLocations lookupTablet(ClientContext context, TabletLocation src, Text row, Text stopRow, TabletLocator parent) throws AccumuloSecurityException, AccumuloException {
    try {
        OpTimer timer = null;
        if (log.isTraceEnabled()) {
            log.trace("tid={} Looking up in {} row={} extent={} tserver={}", Thread.currentThread().getId(), src.tablet_extent.getTableId(), TextUtil.truncate(row), src.tablet_extent, src.tablet_location);
            timer = new OpTimer().start();
        }
        Range range = new Range(row, true, stopRow, true);
        TreeMap<Key, Value> encodedResults = new TreeMap<>();
        TreeMap<Key, Value> results = new TreeMap<>();
        // Use the whole row iterator so that a partial mutations is not read. The code that extracts locations for tablets does a sanity check to ensure there is
        // only one location. Reading a partial mutation could make it appear there are multiple locations when there are not.
        List<IterInfo> serverSideIteratorList = new ArrayList<>();
        serverSideIteratorList.add(new IterInfo(10000, WholeRowIterator.class.getName(), "WRI"));
        Map<String, Map<String, String>> serverSideIteratorOptions = Collections.emptyMap();
        boolean more = ThriftScanner.getBatchFromServer(context, range, src.tablet_extent, src.tablet_location, encodedResults, locCols, serverSideIteratorList, serverSideIteratorOptions, Constants.SCAN_BATCH_SIZE, Authorizations.EMPTY, false, 0L, null);
        decodeRows(encodedResults, results);
        if (more && results.size() == 1) {
            range = new Range(results.lastKey().followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME), true, new Key(stopRow).followingKey(PartialKey.ROW), false);
            encodedResults.clear();
            more = ThriftScanner.getBatchFromServer(context, range, src.tablet_extent, src.tablet_location, encodedResults, locCols, serverSideIteratorList, serverSideIteratorOptions, Constants.SCAN_BATCH_SIZE, Authorizations.EMPTY, false, 0L, null);
            decodeRows(encodedResults, results);
        }
        if (timer != null) {
            timer.stop();
            log.trace("tid={} Got {} results from {} in {}", Thread.currentThread().getId(), results.size(), src.tablet_extent, String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
        }
        return MetadataLocationObtainer.getMetadataLocationEntries(results);
    } catch (AccumuloServerException ase) {
        if (log.isTraceEnabled())
            log.trace("{} lookup failed, {} server side exception", src.tablet_extent.getTableId(), src.tablet_location);
        throw ase;
    } catch (NotServingTabletException e) {
        if (log.isTraceEnabled())
            log.trace("{} lookup failed, {} not serving {}", src.tablet_extent.getTableId(), src.tablet_location, src.tablet_extent);
        parent.invalidateCache(src.tablet_extent);
    } catch (AccumuloException e) {
        if (log.isTraceEnabled())
            log.trace("{} lookup failed", src.tablet_extent.getTableId(), e);
        parent.invalidateCache(context.getInstance(), src.tablet_location);
    }
    return null;
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) ArrayList(java.util.ArrayList) Range(org.apache.accumulo.core.data.Range) TreeMap(java.util.TreeMap) IterInfo(org.apache.accumulo.core.data.thrift.IterInfo) AccumuloServerException(org.apache.accumulo.core.client.impl.AccumuloServerException) OpTimer(org.apache.accumulo.core.util.OpTimer) Value(org.apache.accumulo.core.data.Value) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 15 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class TabletLocatorImpl method binRanges.

@Override
public List<Range> binRanges(ClientContext context, List<Range> ranges, Map<String, Map<KeyExtent, List<Range>>> binnedRanges) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    /*
     * For this to be efficient, need to avoid fine grained synchronization and fine grained logging. Therefore methods called by this are not synchronized and
     * should not log.
     */
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Binning {} ranges for table {}", Thread.currentThread().getId(), ranges.size(), tableId);
        timer = new OpTimer().start();
    }
    LockCheckerSession lcSession = new LockCheckerSession();
    List<Range> failures;
    rLock.lock();
    try {
        processInvalidated(context, lcSession);
        // for this to be optimal, need to look ranges up in sorted order when
        // ranges are not present in cache... however do not want to always
        // sort ranges... therefore try binning ranges using only the cache
        // and sort whatever fails and retry
        failures = binRanges(context, ranges, binnedRanges, true, lcSession);
    } finally {
        rLock.unlock();
    }
    if (failures.size() > 0) {
        // sort failures by range start key
        Collections.sort(failures);
        // try lookups again
        wLock.lock();
        try {
            failures = binRanges(context, failures, binnedRanges, false, lcSession);
        } finally {
            wLock.unlock();
        }
    }
    if (timer != null) {
        timer.stop();
        log.trace("tid={} Binned {} ranges for table {} to {} tservers in {}", Thread.currentThread().getId(), ranges.size(), tableId, binnedRanges.size(), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
    }
    return failures;
}
Also used : OpTimer(org.apache.accumulo.core.util.OpTimer) Range(org.apache.accumulo.core.data.Range)

Aggregations

OpTimer (org.apache.accumulo.core.util.OpTimer)17 ArrayList (java.util.ArrayList)5 Key (org.apache.accumulo.core.data.Key)4 Range (org.apache.accumulo.core.data.Range)4 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)3 Value (org.apache.accumulo.core.data.Value)3 TabletClientService (org.apache.accumulo.core.tabletserver.thrift.TabletClientService)3 HostAndPort (org.apache.accumulo.core.util.HostAndPort)3 Text (org.apache.hadoop.io.Text)3 Entry (java.util.Map.Entry)2 TreeSet (java.util.TreeSet)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2 TKeyValue (org.apache.accumulo.core.data.thrift.TKeyValue)2 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)2 TApplicationException (org.apache.thrift.TApplicationException)2 TException (org.apache.thrift.TException)2 TTransportException (org.apache.thrift.transport.TTransportException)2 IOException (java.io.IOException)1