Ignore:
Timestamp:
2013-04-07T17:07:27+02:00 (12 years ago)
Author:
akks
Message:

JOSM/ImageryCache: updated MapDB (no more deadlocks, Java 1.6 compatible), less crashes, multiple-JOSM support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagerycache/src/org/mapdb/DBMaker.java

    r29363 r29484  
    6060    protected byte[] _xteaEncryptionKey = null;
    6161
    62     protected boolean _freeSpaceReclaimDisabled = false;
     62    protected int _freeSpaceReclaimQ = 5;
    6363
    6464    protected boolean _checksumEnabled = false;
     
    124124                .deleteFilesAfterClose()
    125125                .closeOnJvmShutdown()
    126                 .journalDisable()
     126                .writeAheadLogDisable()
    127127                .make()
    128128                .getTreeMap("temp");
     
    139139                .deleteFilesAfterClose()
    140140                .closeOnJvmShutdown()
    141                 .journalDisable()
     141                .writeAheadLogDisable()
    142142                .make()
    143143                .getHashMap("temp");
     
    154154                .deleteFilesAfterClose()
    155155                .closeOnJvmShutdown()
    156                 .journalDisable()
     156                .writeAheadLogDisable()
    157157                .make()
    158158                .getTreeSet("temp");
     
    169169                .deleteFilesAfterClose()
    170170                .closeOnJvmShutdown()
    171                 .journalDisable()
     171                .writeAheadLogDisable()
    172172                .make()
    173173                .getHashSet("temp");
     
    210210     * @return this builder
    211211     */
    212     public DBMaker journalDisable(){
     212    public DBMaker writeAheadLogDisable(){
    213213        this._journalEnabled = false;
    214214        return this;
     
    485485
    486486    /**
    487      * In this mode existing free space is not reused,
    488      * but records are added to the end of the store.
    489      * <p/>
    490      * This slightly improves write performance as store does not have
    491      * to traverse list of free records to find and reuse existing position.
    492      * <p/>
    493      * It also decreases chance for store corruption, as existing data
    494      * are not overwritten with new record.
    495      * <p/>
    496      * When this mode is used for longer time, store becomes fragmented.
    497      * It is necessary to run defragmentation then.
    498      * <p/>
    499      * NOTE: this mode is not append-only, just small setting for update-in-place storage.
    500      *
    501      *
    502      * @return this builder
    503      */
    504     public DBMaker freeSpaceReclaimDisable(){
    505         this._freeSpaceReclaimDisabled = true;
     487     * Set free space reclaim Q.  It is value from 0 to 10, indicating how eagerly MapDB
     488     * searchs for free space inside store to reuse, before expanding store file.
     489     * 0 means that no free space will be reused and store file will just grow (effectively append only).
     490     * 10 means that MapDB tries really hard to reuse free space, even if it may hurt performance.
     491     * Default value is 5;
     492     *
     493     *
     494     * @return this builder
     495     */
     496    public DBMaker freeSpaceReclaimQ(int q){
     497        if(q<0||q>10) throw new IllegalArgumentException("wrong Q");
     498        this._freeSpaceReclaimQ = q;
    506499        return this;
    507500    }
     
    536529     * @return this builder
    537530     */
    538     public DBMaker powerSavingModeEnable(){
    539         this._powerSavingMode = true;
    540         return this;
    541     }
     531//    public DBMaker powerSavingModeEnable(){
     532//        this._powerSavingMode = true;
     533//        return this;
     534//    }
    542535
    543536
     
    559552            throw new UnsupportedOperationException("Can not open in-memory DB in read-only mode.");
    560553
    561         if(_readOnly && !_file.exists()){
     554        if(_readOnly && !_file.exists() && !_appendStorage){
    562555            throw new UnsupportedOperationException("Can not open non-existing file in read-only mode.");
    563556        }
     
    571564
    572565            engine = _journalEnabled ?
    573                 new StorageJournaled(folFac, _freeSpaceReclaimDisabled, _deleteFilesAfterClose, _failOnWrongHeader, _readOnly):
    574                 new StorageDirect(folFac, _freeSpaceReclaimDisabled, _deleteFilesAfterClose , _failOnWrongHeader, _readOnly);
     566                    //TODO add extra params
     567                //new StoreWAL(folFac, _freeSpaceReclaimDisabled, _deleteFilesAfterClose, _failOnWrongHeader, _readOnly):
     568                //new StoreDirect(folFac, _freeSpaceReclaimDisabled, _deleteFilesAfterClose , _failOnWrongHeader, _readOnly);
     569                new StoreWAL(folFac,  _readOnly,_deleteFilesAfterClose):
     570                new StoreDirect(folFac,  _readOnly,_deleteFilesAfterClose);
    575571        }else{
    576572            if(_file==null) throw new UnsupportedOperationException("Append Storage format is not supported with in-memory dbs");
    577             engine = new StorageAppend(_file, _RAF, _readOnly, !_journalEnabled);
    578         }
     573            engine = new StoreAppend(_file, _RAF, _readOnly, !_journalEnabled);
     574        }
     575
     576        if(_checksumEnabled){
     577            engine = new ByteTransformEngine(engine, Serializer.CRC32_CHECKSUM);
     578        }
     579
     580        if(_xteaEncryptionKey!=null){
     581            engine = new ByteTransformEngine(engine, new EncryptionXTEA(_xteaEncryptionKey));
     582        }
     583
     584
     585        if(_compressionEnabled){
     586            engine = new ByteTransformEngine(engine, CompressLZF.SERIALIZER);
     587        }
     588
    579589
    580590        AsyncWriteEngine engineAsync = null;
     
    584594        }
    585595
    586         if(_checksumEnabled){
    587             engine = new ByteTransformEngine(engine, Serializer.CRC32_CHECKSUM);
    588         }
    589 
    590         if(_xteaEncryptionKey!=null){
    591             engine = new ByteTransformEngine(engine, new EncryptionXTEA(_xteaEncryptionKey));
    592         }
    593 
    594 
    595         if(_compressionEnabled){
    596             engine = new ByteTransformEngine(engine, CompressLZF.SERIALIZER);
    597         }
    598596
    599597        engine = new SnapshotEngine(engine);
     
    625623                @Override
    626624                                public void run() {
     625                   
     626                    // for JOSM plugin ImageryCache
     627                    org.openstreetmap.josm.plugins.imagerycache.TileDAOMapDB.dbNotAvailable = true;
    627628                    if(!engine2.isClosed())
    628629                        engine2.close();
Note: See TracChangeset for help on using the changeset viewer.