test_class.declarator: engine = (StorageDirect) super.engine
test_class.original_string: StorageDirect engine = (StorageDirect) super.engine;
test_class.type: StorageDirect
test_class.var_name: engine
test_class.declarator: TEST_LS_RECID = StorageDirect.RECID_FREE_PHYS_RECORDS_START+1
test_class.modifier: static final
test_class.original_string: static final long TEST_LS_RECID = StorageDirect.RECID_FREE_PHYS_RECORDS_START+1 ;
test_class.type: long
test_class.var_name: TEST_LS_RECID
test_class.file: migration/third-party/org.mapdb/src/test/java/org/mapdb/StorageDirectTest.java
test_class.identifier: StorageDirectTest
test_class.superclass: extends StorageTestCase
test_case.body: @Test public void compact(){
          Map<Long,Long> recids = new HashMap<Long, Long>();
          for(Long l=0L;l<1000;l++){
              recids.put(l,
                      engine.put(l, Serializer.LONG_SERIALIZER));
          }
  
          engine.commit();
          engine.compact();
  
          for(Map.Entry<Long,Long> e:recids.entrySet()){
              Long recid= e.getValue();
              Long value = e.getKey();
              assertEquals(value, engine.get(recid, Serializer.LONG_SERIALIZER));
          }
  
  
      }
test_case.class_method_signature: StorageDirectTest.compact()
test_case.full_signature: @Test public void compact()
test_case.identifier: compact
test_case.invocations: put put commit compact entrySet getValue getKey assertEquals get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void compact()
focal_class.declarator: PHYS_OFFSET_MASK = 0x0000FFFFFFFFFFFFL
focal_class.modifier: static final
focal_class.original_string: static final long PHYS_OFFSET_MASK = 0x0000FFFFFFFFFFFFL;
focal_class.type: long
focal_class.var_name: PHYS_OFFSET_MASK
focal_class.declarator: HEADER = 5646556656456456L
focal_class.modifier: static final
focal_class.original_string: static final long HEADER = 5646556656456456L;
focal_class.type: long
focal_class.var_name: HEADER
focal_class.declarator: RECID_CURRENT_PHYS_FILE_SIZE = 1
focal_class.modifier: static final
focal_class.original_string: static final int RECID_CURRENT_PHYS_FILE_SIZE = 1;
focal_class.type: int
focal_class.var_name: RECID_CURRENT_PHYS_FILE_SIZE
focal_class.declarator: RECID_CURRENT_INDEX_FILE_SIZE = 2
focal_class.modifier: static final
focal_class.original_string: static final int RECID_CURRENT_INDEX_FILE_SIZE = 2;
focal_class.type: int
focal_class.var_name: RECID_CURRENT_INDEX_FILE_SIZE
focal_class.declarator: RECID_FREE_INDEX_SLOTS = 3
focal_class.modifier: static final
focal_class.original_string: static final int RECID_FREE_INDEX_SLOTS = 3;
focal_class.type: int
focal_class.var_name: RECID_FREE_INDEX_SLOTS
focal_class.declarator: RECID_FREE_PHYS_RECORDS_START = 20
focal_class.modifier: static final
focal_class.original_string: static final int RECID_FREE_PHYS_RECORDS_START = 20;
focal_class.type: int
focal_class.var_name: RECID_FREE_PHYS_RECORDS_START
focal_class.declarator: NUMBER_OF_PHYS_FREE_SLOT =1000 + 1535
focal_class.modifier: static final
focal_class.original_string: static final int NUMBER_OF_PHYS_FREE_SLOT =1000 + 1535;
focal_class.type: int
focal_class.var_name: NUMBER_OF_PHYS_FREE_SLOT
focal_class.declarator: MAX_RECORD_SIZE = 65535
focal_class.modifier: static final
focal_class.original_string: static final int MAX_RECORD_SIZE = 65535;
focal_class.type: int
focal_class.var_name: MAX_RECORD_SIZE
focal_class.declarator: LONG_STACK_NUM_OF_RECORDS_PER_PAGE = 100
focal_class.modifier: static final
focal_class.original_string: static final byte LONG_STACK_NUM_OF_RECORDS_PER_PAGE = 100;
focal_class.type: byte
focal_class.var_name: LONG_STACK_NUM_OF_RECORDS_PER_PAGE
focal_class.declarator: LONG_STACK_PAGE_SIZE =   8 + LONG_STACK_NUM_OF_RECORDS_PER_PAGE * 8
focal_class.modifier: static final
focal_class.original_string: static final int LONG_STACK_PAGE_SIZE =   8 + LONG_STACK_NUM_OF_RECORDS_PER_PAGE * 8;
focal_class.type: int
focal_class.var_name: LONG_STACK_PAGE_SIZE
focal_class.declarator: INDEX_OFFSET_START = RECID_FREE_PHYS_RECORDS_START +NUMBER_OF_PHYS_FREE_SLOT
focal_class.modifier: static final
focal_class.original_string: static final int INDEX_OFFSET_START = RECID_FREE_PHYS_RECORDS_START +NUMBER_OF_PHYS_FREE_SLOT;
focal_class.type: int
focal_class.var_name: INDEX_OFFSET_START
focal_class.declarator: DATA_FILE_EXT = ".p"
focal_class.modifier: public static final
focal_class.original_string: public static final String DATA_FILE_EXT = ".p";
focal_class.type: String
focal_class.var_name: DATA_FILE_EXT
focal_class.declarator: lock = new ReentrantReadWriteLock()
focal_class.modifier: protected final
focal_class.original_string: protected final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
focal_class.type: ReentrantReadWriteLock
focal_class.var_name: lock
focal_class.declarator: appendOnly
focal_class.modifier: protected final
focal_class.original_string: protected final boolean appendOnly;
focal_class.type: boolean
focal_class.var_name: appendOnly
focal_class.declarator: deleteFilesOnExit
focal_class.modifier: protected final
focal_class.original_string: protected final boolean deleteFilesOnExit;
focal_class.type: boolean
focal_class.var_name: deleteFilesOnExit
focal_class.declarator: failOnWrongHeader
focal_class.modifier: protected final
focal_class.original_string: protected final boolean failOnWrongHeader;
focal_class.type: boolean
focal_class.var_name: failOnWrongHeader
focal_class.declarator: readOnly
focal_class.modifier: protected final
focal_class.original_string: protected final boolean readOnly;
focal_class.type: boolean
focal_class.var_name: readOnly
focal_class.declarator: phys
focal_class.modifier: volatile protected
focal_class.original_string: volatile protected Volume phys;
focal_class.type: Volume
focal_class.var_name: phys
focal_class.declarator: index
focal_class.modifier: volatile protected
focal_class.original_string: volatile protected Volume index;
focal_class.type: Volume
focal_class.var_name: index
focal_class.file: migration/third-party/org.mapdb/src/main/java/org/mapdb/StorageDirect.java
focal_class.identifier: StorageDirect
focal_class.interfaces: implements Engine
focal_class.class_method_signature: StorageDirect.StorageDirect(Volume.Factory volFac, boolean appendOnly,
                     boolean deleteFilesOnExit, boolean failOnWrongHeader, boolean readOnly)
focal_class.full_signature: public  StorageDirect(Volume.Factory volFac, boolean appendOnly,
                     boolean deleteFilesOnExit, boolean failOnWrongHeader, boolean readOnly)
focal_class.identifier: StorageDirect
focal_class.modifiers: public
focal_class.parameters: (Volume.Factory volFac, boolean appendOnly,
                     boolean deleteFilesOnExit, boolean failOnWrongHeader, boolean readOnly)
focal_class.signature:  StorageDirect(Volume.Factory volFac, boolean appendOnly,
                     boolean deleteFilesOnExit, boolean failOnWrongHeader, boolean readOnly)
focal_class.class_method_signature: StorageDirect.StorageDirect(Volume.Factory volFac)
focal_class.full_signature: public  StorageDirect(Volume.Factory volFac)
focal_class.identifier: StorageDirect
focal_class.modifiers: public
focal_class.parameters: (Volume.Factory volFac)
focal_class.signature:  StorageDirect(Volume.Factory volFac)
focal_class.class_method_signature: StorageDirect.put(A value, Serializer<A> serializer)
focal_class.full_signature: @Override public long put(A value, Serializer<A> serializer)
focal_class.identifier: put
focal_class.modifiers: @Override public
focal_class.parameters: (A value, Serializer<A> serializer)
focal_class.return: long
focal_class.signature: long put(A value, Serializer<A> serializer)
focal_class.class_method_signature: StorageDirect.putLargeLinkedRecord(DataOutput2 out, long recid)
focal_class.full_signature: private void putLargeLinkedRecord(DataOutput2 out, long recid)
focal_class.identifier: putLargeLinkedRecord
focal_class.modifiers: private
focal_class.parameters: (DataOutput2 out, long recid)
focal_class.return: void
focal_class.signature: void putLargeLinkedRecord(DataOutput2 out, long recid)
focal_class.class_method_signature: StorageDirect.get(long recid, Serializer<A> serializer)
focal_class.full_signature: @Override public A get(long recid, Serializer<A> serializer)
focal_class.identifier: get
focal_class.modifiers: @Override public
focal_class.parameters: (long recid, Serializer<A> serializer)
focal_class.return: A
focal_class.signature: A get(long recid, Serializer<A> serializer)
focal_class.class_method_signature: StorageDirect.update(long recid, A value, Serializer<A> serializer)
focal_class.full_signature: @Override public void update(long recid, A value, Serializer<A> serializer)
focal_class.identifier: update
focal_class.modifiers: @Override public
focal_class.parameters: (long recid, A value, Serializer<A> serializer)
focal_class.return: void
focal_class.signature: void update(long recid, A value, Serializer<A> serializer)
focal_class.class_method_signature: StorageDirect.delete(long recid, Serializer<A> serializer)
focal_class.full_signature: @Override public void delete(long recid, Serializer<A> serializer)
focal_class.identifier: delete
focal_class.modifiers: @Override public
focal_class.parameters: (long recid, Serializer<A> serializer)
focal_class.return: void
focal_class.signature: void delete(long recid, Serializer<A> serializer)
focal_class.class_method_signature: StorageDirect.commit()
focal_class.full_signature: @Override public void commit()
focal_class.identifier: commit
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void commit()
focal_class.class_method_signature: StorageDirect.rollback()
focal_class.full_signature: @Override public void rollback()
focal_class.identifier: rollback
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void rollback()
focal_class.class_method_signature: StorageDirect.longStackTake(final long listRecid)
focal_class.full_signature: protected long longStackTake(final long listRecid)
focal_class.identifier: longStackTake
focal_class.modifiers: protected
focal_class.parameters: (final long listRecid)
focal_class.return: long
focal_class.signature: long longStackTake(final long listRecid)
focal_class.class_method_signature: StorageDirect.longStackPut(final long listRecid, final long offset)
focal_class.full_signature: protected void longStackPut(final long listRecid, final long offset)
focal_class.identifier: longStackPut
focal_class.modifiers: protected
focal_class.parameters: (final long listRecid, final long offset)
focal_class.return: void
focal_class.signature: void longStackPut(final long listRecid, final long offset)
focal_class.class_method_signature: StorageDirect.freePhysRecTake(final int requiredSize)
focal_class.full_signature: protected long freePhysRecTake(final int requiredSize)
focal_class.identifier: freePhysRecTake
focal_class.modifiers: protected
focal_class.parameters: (final int requiredSize)
focal_class.return: long
focal_class.signature: long freePhysRecTake(final int requiredSize)
focal_class.class_method_signature: StorageDirect.writeInitValues()
focal_class.full_signature: private void writeInitValues()
focal_class.identifier: writeInitValues
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void writeInitValues()
focal_class.class_method_signature: StorageDirect.writeLock_checkLocked()
focal_class.full_signature: protected void writeLock_checkLocked()
focal_class.identifier: writeLock_checkLocked
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void writeLock_checkLocked()
focal_class.class_method_signature: StorageDirect.freePhysRecSize2FreeSlot(final int size)
focal_class.full_signature: final int freePhysRecSize2FreeSlot(final int size)
focal_class.identifier: freePhysRecSize2FreeSlot
focal_class.modifiers: final
focal_class.parameters: (final int size)
focal_class.return: int
focal_class.signature: int freePhysRecSize2FreeSlot(final int size)
focal_class.class_method_signature: StorageDirect.close()
focal_class.full_signature: @Override public void close()
focal_class.identifier: close
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void close()
focal_class.class_method_signature: StorageDirect.isClosed()
focal_class.full_signature: @Override public boolean isClosed()
focal_class.identifier: isClosed
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isClosed()
focal_class.class_method_signature: StorageDirect.recordGet2(long indexValue, Volume data, Serializer<A> serializer)
focal_class.full_signature: protected A recordGet2(long indexValue, Volume data, Serializer<A> serializer)
focal_class.identifier: recordGet2
focal_class.modifiers: protected
focal_class.parameters: (long indexValue, Volume data, Serializer<A> serializer)
focal_class.return: A
focal_class.signature: A recordGet2(long indexValue, Volume data, Serializer<A> serializer)
focal_class.class_method_signature: StorageDirect.freePhysRecPut(final long indexValue)
focal_class.full_signature: protected void freePhysRecPut(final long indexValue)
focal_class.identifier: freePhysRecPut
focal_class.modifiers: protected
focal_class.parameters: (final long indexValue)
focal_class.return: void
focal_class.signature: void freePhysRecPut(final long indexValue)
focal_class.class_method_signature: StorageDirect.findFreePhysSlot(int requiredSize)
focal_class.full_signature: protected long findFreePhysSlot(int requiredSize)
focal_class.identifier: findFreePhysSlot
focal_class.modifiers: protected
focal_class.parameters: (int requiredSize)
focal_class.return: long
focal_class.signature: long findFreePhysSlot(int requiredSize)
focal_class.class_method_signature: StorageDirect.compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer)
focal_class.full_signature: @Override public boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer)
focal_class.identifier: compareAndSwap
focal_class.modifiers: @Override public
focal_class.parameters: (long recid, A expectedOldValue, A newValue, Serializer<A> serializer)
focal_class.return: boolean
focal_class.signature: boolean compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer)
focal_class.class_method_signature: StorageDirect.isReadOnly()
focal_class.full_signature: @Override public boolean isReadOnly()
focal_class.identifier: isReadOnly
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isReadOnly()
focal_class.class_method_signature: StorageDirect.unlinkPhysRecord(long indexVal, long recid)
focal_class.full_signature: protected void unlinkPhysRecord(long indexVal, long recid)
focal_class.identifier: unlinkPhysRecord
focal_class.modifiers: protected
focal_class.parameters: (long indexVal, long recid)
focal_class.return: void
focal_class.signature: void unlinkPhysRecord(long indexVal, long recid)
focal_class.class_method_signature: StorageDirect.compact()
focal_class.full_signature: @Override public void compact()
focal_class.identifier: compact
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void compact()
focal_method.body: @Override
      public void compact(){
          if(readOnly) throw new IllegalAccessError();
          if(index.getFile()==null) throw new UnsupportedOperationException("compact not supported for memory storage yet");
          lock.writeLock().lock();
          try{
              //create secondary files for compaction
              //TODO RAF
              //TODO memory based stores
              final File indexFile = index.getFile();
              final File physFile = phys.getFile();
              final boolean isRaf = index instanceof Volume.RandomAccessFileVol;
              Volume.Factory fab = Volume.fileFactory(false, isRaf, new File(indexFile+".compact"));
              StorageDirect store2 = new StorageDirect(fab);
  
              //transfer stack of free recids
              for(long recid =longStackTake(RECID_FREE_INDEX_SLOTS);
                  recid!=0; recid=longStackTake(RECID_FREE_INDEX_SLOTS)){
                  store2.longStackPut(recid, RECID_FREE_INDEX_SLOTS);
              }
  
              //iterate over recids and transfer physical records
              final long indexSize = index.getLong(RECID_CURRENT_INDEX_FILE_SIZE*8)/8;
  
  
              store2.lock.writeLock().lock();
              for(long recid = INDEX_OFFSET_START; recid<indexSize;recid++){
                  //read data from first store
                  long physOffset = index.getLong(recid*8);
                  long physSize = physOffset >>> 48;
                  //TODO linked records larger then 64KB
                  physOffset = physOffset & PHYS_OFFSET_MASK;
  
                  //write index value into second storage
                  store2.index.ensureAvailable(recid*8+8);
  
                  //get free place in second store, and write data there
                  if(physSize!=0){
                      DataInput2 in = phys.getDataInput(physOffset, (int)physSize);
                      long physOffset2 =
                              store2.freePhysRecTake((int)physSize) & PHYS_OFFSET_MASK;
  
                      store2.phys.ensureAvailable((physOffset2 & PHYS_OFFSET_MASK)+physSize);
                      synchronized (in.buf){
                          //copy directly from buffer
                          in.buf.limit((int) (in.pos+physSize));
                          in.buf.position(in.pos);
                          store2.phys.putData(physOffset2, in.buf);
                      }
                      store2.index.putLong(recid*8, (physSize<<48)|physOffset2);
                  }else{
                      //just write zeroes
                      store2.index.putLong(recid*8, 0);
                  }
              }
  
              store2.index.putLong(RECID_CURRENT_INDEX_FILE_SIZE*8, indexSize*8);
  
              File indexFile2 = store2.index.getFile();
              File physFile2 = store2.phys.getFile();
              store2.lock.writeLock().unlock();
              store2.close();
  
              long time = System.currentTimeMillis();
              File indexFile_ = new File(indexFile.getPath()+"_"+time+"_orig");
              File physFile_ = new File(physFile.getPath()+"_"+time+"_orig");
  
              index.close();
              phys.close();
              if(!indexFile.renameTo(indexFile_))throw new InternalError();
              if(!physFile.renameTo(physFile_))throw new InternalError();
  
              if(!indexFile2.renameTo(indexFile))throw new InternalError();
              //TODO process may fail in middle of rename, analyze sequence and add recovery
              if(!physFile2.renameTo(physFile))throw new InternalError();
  
              indexFile_.delete();
              physFile_.delete();
  
              Volume.Factory fac2 = Volume.fileFactory(false, isRaf, indexFile);
              index = fac2.createIndexVolume();
              phys = fac2.createPhysVolume();
  
          }catch(IOException e){
              throw new IOError(e);
          }finally {
              lock.writeLock().unlock();
          }
      }
focal_method.class_method_signature: StorageDirect.compact()
focal_method.full_signature: @Override public void compact()
focal_method.identifier: compact
focal_method.invocations: getFile lock writeLock getFile getFile fileFactory longStackTake longStackTake longStackPut getLong lock writeLock getLong ensureAvailable getDataInput freePhysRecTake ensureAvailable limit position putData putLong putLong putLong getFile getFile unlock writeLock close currentTimeMillis getPath getPath close close renameTo renameTo renameTo renameTo delete delete fileFactory createIndexVolume createPhysVolume unlock writeLock
focal_method.modifiers: @Override public
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void compact()