Changeset 8a001ad for apps


Ignore:
Timestamp:
Apr 6, 2019 3:25:37 PM (12 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
904bf2a
Parents:
2c602fa
Message:

Move all disk i/o to a single thread to prevent very rare errors when running multiple tunnels

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/AccessFilter.java

    r2c602fa r8a001ad  
    77import java.util.Iterator;
    88import java.util.concurrent.atomic.AtomicBoolean;
     9import java.util.concurrent.Executors;
     10import java.util.concurrent.ExecutorService;
    911
    1012import java.io.File;
     
    4244    private static final long SYNC_INTERVAL = 10 * 1000;
    4345
     46    /**
     47     * All disk i/o from all instances of this filter
     48     * happen on this thread (apart from initial load)
     49     */
     50    private static final ExecutorService DISK_WRITER = Executors.newSingleThreadExecutor();
     51
    4452    private final FilterDefinition definition;
    4553    private final I2PAppContext context;
     
    5563     */
    5664    private final Map<Hash, DestTracker> unknownDests = new HashMap<Hash, DestTracker>();
     65
     66    private volatile Syncer syncer;
    5767
    5868    /**
     
    7383        if (timersRunning.compareAndSet(false, true)) {
    7484            new Purger();
    75             new Syncer();
     85            syncer = new Syncer();
    7686        }
    7787    }
     
    8090    public void stop() {
    8191        timersRunning.set(false);
     92        syncer = null;
    8293    }
    8394
     
    201212            if (!timersRunning.get())
    202213                return;
    203             try {
    204                 record();
    205                 reload();
    206                 schedule(SYNC_INTERVAL);
    207             } catch (IOException bad) {
    208                 Log log = context.logManager().getLog(AccessFilter.class);
    209                 log.log(Log.CRIT, "syncing access list failed", bad);
    210             }
    211         }
     214            DISK_WRITER.submit(new Runnable() {
     215                @Override
     216                public void run() {
     217                    try {
     218                        record();
     219                        reload();
     220                        Syncer syncer = AccessFilter.this.syncer;
     221                        if (syncer != null)
     222                            syncer.schedule(SYNC_INTERVAL);
     223                    } catch (IOException bad) {
     224                        Log log = context.logManager().getLog(AccessFilter.class);
     225                       log.log(Log.CRIT, "syncing access list failed", bad);
     226                    }
     227                }
     228            });
     229         }   
    212230    }
    213231}
Note: See TracChangeset for help on using the changeset viewer.