Changeset 6a72c29


Ignore:
Timestamp:
Nov 12, 2016 10:27:34 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a8976d2
Parents:
f69c099
Message:

Profiles: Periodically save (ticket #1328)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/peermanager/PeerManager.java

    rf69c099 r6a72c29  
    1818import java.util.Set;
    1919import java.util.concurrent.ConcurrentHashMap;
     20import java.util.concurrent.atomic.AtomicBoolean;
    2021
    2122import net.i2p.data.Hash;
     
    4445    /** value strings are lower case */
    4546    private final Map<Hash, String> _capabilitiesByPeer;
     47    private final AtomicBoolean _storeLock = new AtomicBoolean();
     48    private volatile long _lastStore;
     49
    4650    private static final long REORGANIZE_TIME = 45*1000;
    4751    private static final long REORGANIZE_TIME_MEDIUM = 123*1000;
     
    5357     */
    5458    private static final long REORGANIZE_TIME_LONG = 351*1000;
     59    private static final long STORE_TIME = 19*60*60*1000;
    5560   
    5661    public static final String TRACKED_CAPS = "" +
     
    98103
    99104    /**
     105     *  Reorganize the profiles. Also periodically store them.
     106     *
    100107     *  This takes too long to run on the SimpleTimer2 queue
    101108     *  @since 0.9.10
    102109     */
    103110    private class ReorgThread extends I2PThread {
    104         private SimpleTimer2.TimedEvent _event;
     111        private final SimpleTimer2.TimedEvent _event;
    105112
    106113        public ReorgThread(SimpleTimer2.TimedEvent event) {
     
    118125            }
    119126            long orgtime = System.currentTimeMillis() - start;
     127            if (_lastStore == 0) {
     128                _lastStore = start;
     129            } else if (start - _lastStore > STORE_TIME) {
     130                _lastStore = start;
     131                try {
     132                    _log.debug("Periodic profile store start");
     133                    storeProfiles();
     134                    _log.debug("Periodic profile store end");
     135                } catch (Throwable t) {
     136                    _log.log(Log.CRIT, "Error storing profiles", t);
     137                }
     138            }
    120139            long uptime = _context.router().getUptime();
    121140            long delay;
     
    131150   
    132151    void storeProfiles() {
    133         Set<Hash> peers = selectPeers();
    134         for (Hash peer : peers) {
    135             storeProfile(peer);
     152        // lock in case shutdown bumps into periodic store
     153        if (!_storeLock.compareAndSet(false, true))
     154            return;
     155        try {
     156            Set<Hash> peers = selectPeers();
     157            for (Hash peer : peers) {
     158                storeProfile(peer);
     159            }
     160        } finally {
     161            _storeLock.set(false);
    136162        }
    137163    }
Note: See TracChangeset for help on using the changeset viewer.