Exemple #1
0
 protected synchronized void removeRecordsOlderThan(long millisInUtc) {
   RW_LOCK.writeLock().lock();
   try {
     if (millisInUtc <= 0 || stopped) {
       return;
     }
     long searchBound = TIME_BASED_KEYS.getCounterEndingAt(millisInUtc);
     LOGGER.debug("Removing records older than " + searchBound);
     NavigableMap<Long, JournalRecord> toRemove = this.records.headMap(searchBound);
     toRemove.clear();
     journalDB.commit();
     journalDB.compact();
   } finally {
     RW_LOCK.writeLock().unlock();
   }
 }
Exemple #2
0
 @Override
 protected void configure() {
   ChangeInfoFormatter changeFormatter;
   try {
     changeFormatter =
         (ChangeInfoFormatter)
             Class.forName(properties.getProperty(Constants.CHANGE_INFO_FORMATTER_CLASS))
                 .getDeclaredConstructor(Properties.class)
                 .newInstance(properties);
   } catch (Exception e) {
     log.warn(
         "unable to load "
             + properties.getProperty(Constants.CHANGE_INFO_FORMATTER_CLASS)
             + " class as a change formatter, using the default one",
         e);
     changeFormatter = new DefaultChangeInfoFormatter(properties);
   }
   DB db = DBMaker.newFileDB(new File("db")).closeOnJvmShutdown().make();
   db.compact();
   bind(DB.class).toInstance(db);
   bind(String.class)
       .annotatedWith(Names.named(Constants.GERRIT_URL))
       .toInstance(properties.getProperty(Constants.GERRIT_URL));
   bind(String.class)
       .annotatedWith(Names.named(Constants.JIRA_URL))
       .toInstance(properties.getProperty(Constants.JIRA_URL));
   bind(String.class)
       .annotatedWith(Names.named(Constants.JIRA_USER))
       .toInstance(properties.getProperty(Constants.JIRA_USER));
   bind(String.class)
       .annotatedWith(Names.named(Constants.JIRA_PASSWORD))
       .toInstance(properties.getProperty(Constants.JIRA_PASSWORD));
   bind(ReviewRequestService.class).to(ReviewRequestServiceImpl.class);
   bind(ProjectSubscriptionService.class).to(ProjectSubscriptionImpl.class);
   bind(ExecutorService.class).toInstance(Executors.newFixedThreadPool(8));
   bind(ChangeInfoFormatter.class).toInstance(changeFormatter);
 }
 /**
  * Create a new interval persister. If file points to an existing database of intervals, it will
  * be reused.
  */
 public IntervalPersister(final File file) {
   this.databaseFile = file;
   try {
     initalizeDatabase(file);
   } catch (Error e) {
     // MapDB wraps every exception inside an Error, so this code is
     // unfortunately necessary.
     try {
       recreateDatabase(file);
     } catch (Error innerError) {
       WatchDogLogger.getInstance().logSevere(innerError);
     }
   }
   try {
     // Compact database on every 10th new interval.
     if (!set.isEmpty() && set.size() % 10 == 0) {
       replaceClassLoader();
       database.compact();
       resetOldClassLoader();
     }
   } catch (Error e) {
     // intentionally left empty.
   }
 }
Exemple #4
0
  @Test
  public void NoSuchElem_After_Clear() {
    //      bug reported by :	Lazaros Tsochatzidis
    //        But after clearing the tree using:
    //
    //        public void Delete() {
    //            db.getTreeMap("Names").clear();
    //            db.compact();
    //        }
    //
    //        every next call of getLastKey() leads to the exception "NoSuchElement". Not
    //        only the first one...

    DB db = DBMaker.memoryDB().transactionDisable().make();
    NavigableMap m = db.treeMap("name");
    try {
      m.lastKey();
      fail();
    } catch (NoSuchElementException e) {
    }
    m.put("aa", "aa");
    assertEquals("aa", m.lastKey());
    m.put("bb", "bb");
    assertEquals("bb", m.lastKey());
    db.treeMap("name").clear();
    db.compact();
    try {
      Object key = m.lastKey();
      fail(key.toString());
    } catch (NoSuchElementException e) {
    }
    m.put("aa", "aa");
    assertEquals("aa", m.lastKey());
    m.put("bb", "bb");
    assertEquals("bb", m.lastKey());
  }
 public void compact() {
   db.compact();
 }