void BlockDataManagerConfig::parseArgs(int argc, char* argv[])
{
/***
--testnet: run db against testnet bitcoin network
--regtest: run db against regression test network
--rescan: delete all processed history data and rescan blockchain from the
first block
--rebuild: delete all DB data and build and scan from scratch
--rescanSSH: delete balance and txcount data and rescan it. Much faster than
rescan or rebuild.
--datadir: path to the operation folder
--dbdir: path to folder containing the database files. If empty, a new db
will be created there
--satoshi-datadir: path to blockchain data folder (blkXXXXX.dat files)
--ram_usage: defines the ram use during scan operations. 1 level averages
128MB of ram (without accounting the base amount, ~400MB). Defaults at 4.
Can't be lower than 1. Can be changed in between processes
--thread-count: defines how many processing threads can be used during db
builds and scans. Defaults to maximum available CPU threads. Can't be
lower than 1. Can be changed in between processes
--zcthread-count: defines the maximum number on threads the zc parser can
create for processing incoming transcations from the network node
--db-type: sets the db type:
DB_BARE: tracks wallet history only. Smallest DB.
DB_FULL: tracks wallet history and resolves all relevant tx hashes.
~750MB DB at the time of 0.95 release. Default DB type.
DB_SUPER: tracks all blockchain history. XXL DB (100GB+).
Not implemented yet
db type cannot be changed in between processes. Once a db has been built
with a certain type, it will always function according to that type.
Specifying another type will do nothing. Build a new db to change type.
--cookie: create a cookie file holding a random authentication key to allow
local clients to make use of elevated commands, like shutdown.
--fcgi-port: sets the DB listening port.
--clear-mempool: delete all zero confirmation transactions from the DB.
***/
try
{
//parse cli args
map<string, string> args;
for (int i = 1; i < argc; i++)
{
//check prefix
if (strlen(argv[i]) < 2)
throw DbErrorMsg("invalid CLI arg");
string prefix(argv[i], 2);
if (prefix != "--")
throw DbErrorMsg("invalid CLI arg");
//string prefix and tokenize
string line(argv[i] + 2);
auto&& argkeyval = getKeyValFromLine(line, '=');
args.insert(make_pair(
argkeyval.first, stripQuotes(argkeyval.second)));
}
processArgs(args, true);
//figure out datadir
auto argIter = args.find("datadir");
if (argIter != args.end())
{
dataDir_ = argIter->second;
args.erase(argIter);
}
else
{
if (!testnet_ && !regtest_)
dataDir_ = defaultDataDir_;
else if (!regtest_)
dataDir_ = defaultTestnetDataDir_;
else
dataDir_ = defaultRegtestDataDir_;
}
expandPath(dataDir_);
//get datadir
auto configPath = dataDir_;
appendPath(configPath, "armorydb.conf");
if (DBUtils::fileExists(configPath, 2))
//.........这里部分代码省略.........
PRBool nsDefaultURIFixup::MakeAlternateURI(nsIURI *aURI)
{
if (!mPrefBranch)
{
return PR_FALSE;
}
PRBool makeAlternate = PR_TRUE;
mPrefBranch->GetBoolPref("browser.fixup.alternate.enabled", &makeAlternate);
if (!makeAlternate)
{
return PR_FALSE;
}
// Code only works for http. Not for any other protocol including https!
PRBool isHttp = PR_FALSE;
aURI->SchemeIs("http", &isHttp);
if (!isHttp) {
return PR_FALSE;
}
// Security - URLs with user / password info should NOT be fixed up
nsCAutoString userpass;
aURI->GetUserPass(userpass);
if (!userpass.IsEmpty()) {
return PR_FALSE;
}
nsCAutoString oldHost;
nsCAutoString newHost;
aURI->GetHost(oldHost);
// Count the dots
PRInt32 numDots = 0;
nsReadingIterator<char> iter;
nsReadingIterator<char> iterEnd;
oldHost.BeginReading(iter);
oldHost.EndReading(iterEnd);
while (iter != iterEnd) {
if (*iter == '.')
numDots++;
++iter;
}
nsresult rv;
// Get the prefix and suffix to stick onto the new hostname. By default these
// are www. & .com but they could be any other value, e.g. www. & .org
nsCAutoString prefix("www.");
nsXPIDLCString prefPrefix;
rv = mPrefBranch->GetCharPref("browser.fixup.alternate.prefix", getter_Copies(prefPrefix));
if (NS_SUCCEEDED(rv))
{
prefix.Assign(prefPrefix);
}
nsCAutoString suffix(".com");
nsXPIDLCString prefSuffix;
rv = mPrefBranch->GetCharPref("browser.fixup.alternate.suffix", getter_Copies(prefSuffix));
if (NS_SUCCEEDED(rv))
{
suffix.Assign(prefSuffix);
}
if (numDots == 0)
{
newHost.Assign(prefix);
newHost.Append(oldHost);
newHost.Append(suffix);
}
else if (numDots == 1)
{
if (!prefix.IsEmpty() &&
oldHost.EqualsIgnoreCase(prefix.get(), prefix.Length())) {
newHost.Assign(oldHost);
newHost.Append(suffix);
}
else if (!suffix.IsEmpty()) {
newHost.Assign(prefix);
newHost.Append(oldHost);
}
else
{
// Do nothing
return PR_FALSE;
}
}
else
{
// Do nothing
return PR_FALSE;
}
if (newHost.IsEmpty()) {
return PR_FALSE;
}
// Assign the new host string over the old one
aURI->SetHost(newHost);
//.........这里部分代码省略.........
RocksEngine::RocksEngine(const std::string& path, bool durable)
: _path(path), _durable(durable), _maxPrefix(0) {
{ // create block cache
uint64_t cacheSizeGB = rocksGlobalOptions.cacheSizeGB;
if (cacheSizeGB == 0) {
ProcessInfo pi;
unsigned long long memSizeMB = pi.getMemSizeMB();
if (memSizeMB > 0) {
double cacheMB = memSizeMB / 2;
cacheSizeGB = static_cast<uint64_t>(cacheMB / 1024);
}
if (cacheSizeGB < 1) {
cacheSizeGB = 1;
}
}
_block_cache = rocksdb::NewLRUCache(cacheSizeGB * 1024 * 1024 * 1024LL, 6);
}
_maxWriteMBPerSec = rocksGlobalOptions.maxWriteMBPerSec;
_rateLimiter.reset(
rocksdb::NewGenericRateLimiter(static_cast<int64_t>(_maxWriteMBPerSec) * 1024 * 1024));
// open DB
rocksdb::DB* db;
auto s = rocksdb::DB::Open(_options(), path, &db);
invariantRocksOK(s);
_db.reset(db);
_counterManager.reset(
new RocksCounterManager(_db.get(), rocksGlobalOptions.crashSafeCounters));
_compactionScheduler.reset(new RocksCompactionScheduler(_db.get()));
// open iterator
boost::scoped_ptr<rocksdb::Iterator> iter(_db->NewIterator(rocksdb::ReadOptions()));
// find maxPrefix
iter->SeekToLast();
if (iter->Valid()) {
// otherwise the DB is empty, so we just keep it at 0
bool ok = extractPrefix(iter->key(), &_maxPrefix);
// this is DB corruption here
invariant(ok);
}
// load ident to prefix map. also update _maxPrefix if there's any prefix bigger than
// current _maxPrefix
{
boost::lock_guard<boost::mutex> lk(_identPrefixMapMutex);
for (iter->Seek(kMetadataPrefix);
iter->Valid() && iter->key().starts_with(kMetadataPrefix); iter->Next()) {
invariantRocksOK(iter->status());
rocksdb::Slice ident(iter->key());
ident.remove_prefix(kMetadataPrefix.size());
// this could throw DBException, which then means DB corruption. We just let it fly
// to the caller
BSONObj identConfig(iter->value().data());
BSONElement element = identConfig.getField("prefix");
if (element.eoo() || !element.isNumber()) {
log() << "Mongo metadata in RocksDB database is corrupted.";
invariant(false);
}
uint32_t identPrefix = static_cast<uint32_t>(element.numberInt());
_identPrefixMap[StringData(ident.data(), ident.size())] = identPrefix;
_maxPrefix = std::max(_maxPrefix, identPrefix);
}
}
// just to be extra sure. we need this if last collection is oplog -- in that case we
// reserve prefix+1 for oplog key tracker
++_maxPrefix;
// load dropped prefixes
{
rocksdb::WriteBatch wb;
// we will use this iter to check if prefixes are still alive
boost::scoped_ptr<rocksdb::Iterator> prefixIter(
_db->NewIterator(rocksdb::ReadOptions()));
for (iter->Seek(kDroppedPrefix);
iter->Valid() && iter->key().starts_with(kDroppedPrefix); iter->Next()) {
invariantRocksOK(iter->status());
rocksdb::Slice prefix(iter->key());
prefix.remove_prefix(kDroppedPrefix.size());
prefixIter->Seek(prefix);
invariantRocksOK(iter->status());
if (prefixIter->Valid() && prefixIter->key().starts_with(prefix)) {
// prefix is still alive, let's instruct the compaction filter to clear it up
uint32_t int_prefix;
bool ok = extractPrefix(prefix, &int_prefix);
invariant(ok);
{
boost::lock_guard<boost::mutex> lk(_droppedPrefixesMutex);
_droppedPrefixes.insert(int_prefix);
}
} else {
// prefix is no longer alive. let's remove the prefix from our dropped prefixes
// list
wb.Delete(iter->key());
}
}
//.........这里部分代码省略.........
请发表评论