@Override
    public void setSnapshot(final SnapshotMeta meta) {
        LOG.debug("set snapshot: {}.", meta);
        boolean doUnlock = true;
        this.writeLock.lock();
        try {
            if (meta.getLastIncludedIndex() <= this.lastSnapshotId.getIndex()) {
                return;
            }
            final Configuration conf = confFromMeta(meta);
            final Configuration oldConf = oldConfFromMeta(meta);

            final ConfigurationEntry entry = new ConfigurationEntry(new LogId(meta.getLastIncludedIndex(),
                meta.getLastIncludedTerm()), conf, oldConf);
            this.configManager.setSnapshot(entry);
            final long term = unsafeGetTerm(meta.getLastIncludedIndex());
            final long savedLastSnapshotIndex = this.lastSnapshotId.getIndex();

            this.lastSnapshotId.setIndex(meta.getLastIncludedIndex());
            this.lastSnapshotId.setTerm(meta.getLastIncludedTerm());

            if (this.lastSnapshotId.compareTo(this.appliedId) > 0) {
                this.appliedId = this.lastSnapshotId.copy();
            }
            // NOTICE: not to update disk_id here as we are not sure if this node really
            // has these logs on disk storage. Just leave disk_id as it was, which can keep
            // these logs in memory all the time until they are flushed to disk. By this
            // way we can avoid some corner cases which failed to get logs.
            // See https://github.com/baidu/braft/pull/224/commits/8ef6fdbf70d23f5a4ee147356a889e2c0fa22aac
            //            if (this.lastSnapshotId.compareTo(this.diskId) > 0) {
            //                this.diskId = this.lastSnapshotId.copy();
            //            }

            if (term == 0) {
                // last_included_index is larger than last_index
                // FIXME: what if last_included_index is less than first_index?
                doUnlock = false;
                //unlock in truncatePrefix
                truncatePrefix(meta.getLastIncludedIndex() + 1, this.writeLock);
            } else if (term == meta.getLastIncludedTerm()) {
                // Truncating log to the index of the last snapshot.
                // We don't truncate log before the last snapshot immediately since
                // some log around last_snapshot_index is probably needed by some
                // followers
                // TODO if there are still be need?
                if (savedLastSnapshotIndex > 0) {
                    doUnlock = false;
                    //unlock in truncatePrefix
                    truncatePrefix(savedLastSnapshotIndex + 1, this.writeLock);
                }
            } else {
                if (!reset(meta.getLastIncludedIndex() + 1)) {
                    LOG.warn("Reset log manager failed, nextLogIndex={}.", meta.getLastIncludedIndex() + 1);
                }
            }
        } finally {
            if (doUnlock) {
                this.writeLock.unlock();
            }
        }

    }
Adds event to disk queue, NEVER call it in lock.
@param done
@param type
jraft-core/src/main/java/com/alipay/sofa/jraft/storage/impl/LogManagerImpl.java