Search in sources :

Example 1 with StoredSortedMap

use of com.sleepycat.collections.StoredSortedMap in project heritrix3 by internetarchive.

the class PersistProcessor method populatePersistEnvFromLog.

/**
 * Populates an environment db from a persist log. If historyMap is
 * not provided, only logs the entries that would have been populated.
 *
 * @param persistLogReader
 *            persist log
 * @param historyMap
 *            new environment db (or null for a dry run)
 * @return number of records
 * @throws UnsupportedEncodingException
 * @throws DatabaseException
 */
private static int populatePersistEnvFromLog(BufferedReader persistLogReader, StoredSortedMap<String, Map> historyMap) throws UnsupportedEncodingException, DatabaseException {
    int count = 0;
    Iterator<String> iter = new LineReadingIterator(persistLogReader);
    while (iter.hasNext()) {
        String line = iter.next();
        if (line.length() == 0) {
            continue;
        }
        String[] splits = line.split(" ");
        if (splits.length != 2) {
            logger.severe("bad line has " + splits.length + " fields (should be 2): " + line);
            continue;
        }
        Map alist;
        try {
            alist = (Map) SerializationUtils.deserialize(Base64.decodeBase64(splits[1].getBytes("UTF-8")));
        } catch (Exception e) {
            logger.severe("caught exception " + e + " deserializing line: " + line);
            continue;
        }
        if (logger.isLoggable(Level.FINE)) {
            logger.fine(splits[0] + " " + ArchiveUtils.prettyString(alist));
        }
        if (historyMap != null)
            try {
                historyMap.put(splits[0], alist);
            } catch (Exception e) {
                logger.log(Level.SEVERE, "caught exception after loading " + count + " urls from the persist log (perhaps crawl was stopped by user?)", e);
                IOUtils.closeQuietly(persistLogReader);
                // seems to finish most cleanly when we return rather than throw something
                return count;
            }
        count++;
    }
    IOUtils.closeQuietly(persistLogReader);
    return count;
}
Also used : LineReadingIterator(org.archive.util.iterator.LineReadingIterator) Map(java.util.Map) StoredSortedMap(com.sleepycat.collections.StoredSortedMap) DatabaseException(com.sleepycat.je.DatabaseException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with StoredSortedMap

use of com.sleepycat.collections.StoredSortedMap in project heritrix3 by internetarchive.

the class BdbContentDigestHistory method start.

@Override
@SuppressWarnings("rawtypes")
public void start() {
    if (isRunning()) {
        return;
    }
    StoredSortedMap<String, Map> historyMap;
    try {
        StoredClassCatalog classCatalog = bdb.getClassCatalog();
        historyDb = bdb.openDatabase(getHistoryDbName(), historyDbConfig(), true);
        historyMap = new StoredSortedMap<String, Map>(historyDb, new StringBinding(), new SerialBinding<Map>(classCatalog, Map.class), true);
    } catch (DatabaseException e) {
        throw new RuntimeException(e);
    }
    store = historyMap;
}
Also used : StringBinding(com.sleepycat.bind.tuple.StringBinding) StoredClassCatalog(com.sleepycat.bind.serial.StoredClassCatalog) SerialBinding(com.sleepycat.bind.serial.SerialBinding) StoredSortedMap(com.sleepycat.collections.StoredSortedMap) HashMap(java.util.HashMap) Map(java.util.Map) DatabaseException(com.sleepycat.je.DatabaseException)

Example 3 with StoredSortedMap

use of com.sleepycat.collections.StoredSortedMap in project heritrix3 by internetarchive.

the class ObjectIdentityBdbManualCache method createDiskMap.

@SuppressWarnings("unchecked")
protected StoredSortedMap<String, V> createDiskMap(Database database, StoredClassCatalog classCatalog, Class valueClass) {
    EntryBinding keyBinding = TupleBinding.getPrimitiveBinding(String.class);
    EntryBinding valueBinding = TupleBinding.getPrimitiveBinding(valueClass);
    if (valueBinding == null) {
        valueBinding = new KryoBinding<V>(valueClass);
    // new SerialBinding(classCatalog, valueClass);
    // new BenchmarkingBinding<V>(new EntryBinding[] {
    // new KryoBinding<V>(valueClass),
    // new RecyclingSerialBinding<V>(classCatalog, valueClass),
    // }, valueClass);
    }
    return new StoredSortedMap<String, V>(database, keyBinding, valueBinding, true);
}
Also used : EntryBinding(com.sleepycat.bind.EntryBinding) StoredSortedMap(com.sleepycat.collections.StoredSortedMap)

Example 4 with StoredSortedMap

use of com.sleepycat.collections.StoredSortedMap in project heritrix3 by internetarchive.

the class PreloadedUriPrecedencePolicy method start.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void start() {
    if (isRunning()) {
        return;
    }
    store = null;
    String dbName = PersistProcessor.URI_HISTORY_DBNAME;
    try {
        StoredClassCatalog classCatalog = bdb.getClassCatalog();
        BdbModule.BdbConfig dbConfig = PersistProcessor.HISTORY_DB_CONFIG;
        historyDb = bdb.openDatabase(dbName, dbConfig, true);
        SerialBinding sb = new SerialBinding(classCatalog, Map.class);
        StoredSortedMap historyMap = new StoredSortedMap(historyDb, new StringBinding(), sb, true);
        store = historyMap;
    } catch (DatabaseException e) {
        throw new RuntimeException(e);
    }
}
Also used : BdbModule(org.archive.bdb.BdbModule) StringBinding(com.sleepycat.bind.tuple.StringBinding) StoredClassCatalog(com.sleepycat.bind.serial.StoredClassCatalog) SerialBinding(com.sleepycat.bind.serial.SerialBinding) StoredSortedMap(com.sleepycat.collections.StoredSortedMap) DatabaseException(com.sleepycat.je.DatabaseException)

Example 5 with StoredSortedMap

use of com.sleepycat.collections.StoredSortedMap in project heritrix3 by internetarchive.

the class PrefixFinderTest method testStoredSortedMap.

public void testStoredSortedMap() throws Exception {
    EnvironmentConfig config = new EnvironmentConfig();
    config.setAllowCreate(true);
    config.setCachePercent(5);
    File f = new File(getTmpDir(), "PrefixFinderText");
    FileUtils.deleteQuietly(f);
    org.archive.util.FileUtils.ensureWriteableDirectory(f);
    Environment bdbEnvironment = new Environment(f, config);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    dbConfig.setDeferredWrite(true);
    Database db = bdbEnvironment.openDatabase(null, "test", dbConfig);
    StoredSortedMap<String, String> ssm = new StoredSortedMap<String, String>(db, new StringBinding(), new StringBinding(), true);
    testUrlsNoMatch(ssm);
    db.close();
    bdbEnvironment.close();
}
Also used : StringBinding(com.sleepycat.bind.tuple.StringBinding) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) File(java.io.File) StoredSortedMap(com.sleepycat.collections.StoredSortedMap) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Aggregations

StoredSortedMap (com.sleepycat.collections.StoredSortedMap)9 StringBinding (com.sleepycat.bind.tuple.StringBinding)7 StoredClassCatalog (com.sleepycat.bind.serial.StoredClassCatalog)6 Map (java.util.Map)6 SerialBinding (com.sleepycat.bind.serial.SerialBinding)5 Database (com.sleepycat.je.Database)4 DatabaseException (com.sleepycat.je.DatabaseException)4 File (java.io.File)3 EnhancedEnvironment (org.archive.util.bdbje.EnhancedEnvironment)3 DatabaseConfig (com.sleepycat.je.DatabaseConfig)2 HashMap (java.util.HashMap)2 BdbModule (org.archive.bdb.BdbModule)2 LineReadingIterator (org.archive.util.iterator.LineReadingIterator)2 EntryBinding (com.sleepycat.bind.EntryBinding)1 Environment (com.sleepycat.je.Environment)1 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Entry (java.util.Map.Entry)1