Rotate Delete:
[WIP] Add 'visitNodes' function and implement 'visitLeaves' with it
(this specific commit was David Schwartz. All subsequent Mark Travis)

Add config sections for rotate-delete:
[rotate_delete] #: number of ledgers in between rotation intervals
[keep_ledgers] #: number of recent ledgers to keep when deleting
[advisory_delete] 0|1: if enabled, require rpc call (not yet implemented)
to indicate the latest allowable ledger to delete

add RotateDelete class

launch RotateDelete thread

In RotateDelete, recover database and rotation state from shutdown or crash,
clean old database directories, start new backend if no previous database

Remove rocksdb contents and directory in destructor.

function to copy rotate of ledger from previous to current backend

some logic in rotation loop

WIP need cross-platform way to open file for writing to get file descriptor
for fsync()

write dbstate, rotation logic

Database::copyToCurrent(). Broken, need to modify fetchInternal() next.

WIP DatabaseImpl::fetchInternalRotateDelete()

database functions work with rotate-delete (fetch, store)

no batch writes for rotate delete in RocksDB

log RocksDB errors

rpc command "can_delete" used with ADVISORY_DELETE to let user allow
the earliest ledger to delete

remove [keep_ledgers] config, use [ledger_history] instead

don't start if [rotate_delete] is set and [ledger_history] is full

write dbStateFile for non-POSIX platforms. Does not write synchronously.

formatting cleanup

setup SQLite to persist rotate db state

can_delete RPC uses SQLite to set/get deletable ledger

[WIP] functions added to RotateDelete to replace monolithic functor

uncomment copyToCurrent

modularize RotateDelete::operator()() components

remove unused code

debug RotateDelete

Add config options to example config. Add log entries for RotateDelete.

modify log message.node.getString() changed recently

fix CREATE TABLE so all 5 columns are created

no need for <memory> header

clarify comment

fix SQL and add debugging messages

create [node_db] path if it doesn't exist for [rotate_delete]

fix SQL and return from cleanDbs if the path doesn't exist

remove logging entries

remove trailing whitespace

default journal mode for rotate.db and remove duplicate semi-colon

fetch currentdb before previous

remove gratuitous ;

keeping 2 backends at all times for rotation

non-portable, debugging only print memory usage looking for leak

WIP troubleshooting unbounded memory growth in rotation process

troubleshooting unbounded memory, using recursive shamap walker

go back to using visitNodes

use validated instead of closed ledger for rotation

print mem location for new rocksdb instances, for finding possible leaks with gdb

baseline for memory growth tests: 1 visitNodes

test 2: 2 calls to fetchInternalRotateDelete from copyToCurrent

test 3: copyToCurrent does fetchInternalRotateDelete(), getFromCurrent(), getFromPrevious()

back to baseline: 1 fetchInternal cal from copyToCurrent

delete RocksDB bloom filter_policy

declare m_filter_policy so it gets destroyed after m_db in destructor

remove unnecessary .reset() in destructor

debug, non-portable, add mtrace()

remove mtrace(): too heavy, can't even sync with network initially

roate delete checking starts once there's a validated ledger

[NON-PORTABLE] link jemalloc

test heap profile

change location of heap profile

heap dump placement

delete hyperleveldb on rotation

count and log leak-making function entry points

print every fetch

can I even print to stderr from rocksdb?

log leaky object creation

print created and deleted leaky objects

log raw_block locations where likely to leak

more log, make stderr

disable filling rocksdb cache on fetch (test to avoid memory leak)

re-enable rocksdb cache for test

Use os.path.join() for environment modification.

put profiling in preprocessor conditional block, disable rocksdb caching

use rocksdb cache

print leaky block pointer address in a log message

looking for flow

more log

fill_cache = false

fill_cache = true (default), and DeleteHeldResource for leaky objects

set fill_cache to false

fill_cache = false (don't want memory growth)

add index to prepare for range deletion

delete old ledgers and transactions from SQLite

log start and stop of deleting from SQLite databases, because a lock is held

log every store() of a node, log SHAMapMissingNode prior to exception

don't miss nodes in open ledger

don't re-initialize currentSeq

wait less for new validated ledger

assert on missing node map to get stack trace

use recursive walker, and log each write it does

clear suppression cache during rotate delete

remove entry from negative cache when doing copyToCurrent, log backend for writes

fix scope of log entry

use visitNodes instead of walker

make sure copy to new backend is on the latest validated ledger

assert() on SHAMapMissingNode to get stack trace

use walker

use visitNodes. this is as or more stable than walker

set fill_cache false in hyperleveldb for comparison

atomically store and clear neg cache. atomically rotate backend and clear
suppression cache

clear caches

log before shamap missing node

typo

remove whitespace and test dropping

fix whitespace and merge conflict

fix clearing of suppression map

fixes for merge

functions to freshen caches during rotation

remove blank line

Ensure unbacked trees acquire fully resident

copy ledger and freshen all caches

delete old ledger records, make new backend, make old backend placeholder

rotate and delete

update last rotated ledger

re-add improper git merge deletes

properly clean up backend object

enable rocksdb cache

copy transaction map (in addition to account map) in rotate-delete

disable rocksdb cache

[FOLD] Rotate/Delete fixes
Freshen the full below cache
Limit peer fetches based on rotate interval

Clear LedgerCache of historical ledgers.

Option to configure use of RocksDB cache

clear (not freshen) FullBelowCache

Check return value for each step to acquire ledger snapShot()

Log correct new backend db name

Persist nodes in filter regardless of canonicalization.

Catch, and log, and raise on missing node during rotate-delete. Don't raise
in the underlying function.

Fix how ledger to copy is identified by rotate delete.

Fix git regression, lock correct sqlite db

Add log entries for precursor functions to node storage.

Ignore Full Below for testing whether to walk through missing nodes.

Don't copy transaction map.

[EXPERIMENTAL] Remove full below flag from SHAMapTreeNode's.

Log node state on path to persistence, or not.

Ignore Full Below for testing whether to walk through missing nodes.
roll back from [EXPERIMENTAL] Remove full below flag from SHAMapTreeNode's,
but keep only ignore full below in walking through getMissingNodes()

Conflicts:
	src/ripple/module/app/shamap/SHAMapSync.cpp

Manually revert "[EXPERIMENTAL] Remove full below flag from SHAMapTreeNode's."
other than check during shamap walk in getMissingNodes()

Force persist nodes in tree node cache.

Serialize node to get persisted.

Don't check for node type.

Log prior to the call to persist node.

Don't check type on something that might be null.

Try to fetch before deciding to persist.

Logging fetched, so not store.

Persist if in mTNByID

Fetch first.

Remove mostly redundant node persisting.

Clear caches within rotate-delete mutex. Clear them just prior to minimize
size when they get cleared within the lock.

Fix conditional for logging node in full below.

Change full below from a flag to a version for comparison with
rotate-delete intervals.

Fix check for determining full below validity.

Fix comparison for full below validity.

Fix how FullBelowValid is set. Add correct conditions for checking
if full below.

Ensure persistence upon insert into tree node cache.

Make sure account nodes only get re-persisted after tree node cache.

Avoid crash from getting ledger index before current ledger exists.

Persist tree-node cache inserts wihout checking type,
freshen caches after rotate (as well as before)

Undo SHAMap changes in preparation for rebases.

Fixes for building with latest rebase.