Example #1
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformClientExport);
	set_exception_handler();
	
	LogFile->write(EQEMuLog::Status, "Client Files Export Utility");
	if(!EQEmuConfig::LoadConfig()) {
		LogFile->write(EQEMuLog::Error, "Unable to load configuration file.");
		return 1;
	}

	const EQEmuConfig *config = EQEmuConfig::get();
	if(!load_log_settings(config->LogSettingsFile.c_str())) {
		LogFile->write(EQEMuLog::Error, "Warning: unable to read %s.", config->LogSettingsFile.c_str());
	}

	SharedDatabase database;
	LogFile->write(EQEMuLog::Status, "Connecting to database...");
	if(!database.Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(),
		config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) {
		LogFile->write(EQEMuLog::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 1;
	}
	
	ExportSpells(&database);
	ExportSkillCaps(&database);
	ExportBaseData(&database);
	
	return 0;
}
Example #2
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformClientExport);
	Log.LoadLogSettingsDefaults();
	set_exception_handler();

	Log.Out(Logs::General, Logs::Status, "Client Files Export Utility");
	if(!EQEmuConfig::LoadConfig()) {
		Log.Out(Logs::General, Logs::Error, "Unable to load configuration file.");
		return 1;
	}

	const EQEmuConfig *config = EQEmuConfig::get();

	SharedDatabase database;
	Log.Out(Logs::General, Logs::Status, "Connecting to database...");
	if(!database.Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(),
		config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) {
		Log.Out(Logs::General, Logs::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 1;
	}

	/* Register Log System and Settings */
	database.LoadLogSettings(Log.log_settings);
	Log.StartFileLogs();

	ExportSpells(&database);
	ExportSkillCaps(&database);
	ExportBaseData(&database);

	Log.CloseFileLogs();

	return 0;
}
Example #3
0
void CmdInterpreter::visit(ProxyCmdGetTxnCsn &cmd)
{
    TxnHandle *pTxnHandle = getTxnHandle(cmd.getTxnHandle());
    SharedDatabase pDb = pTxnHandle->pDb;
    assert(pDb->areSnapshotsEnabled());
    SnapshotRandomAllocationSegment *pSegment =
        SegmentFactory::dynamicCast<SnapshotRandomAllocationSegment *>(
            pTxnHandle->pSnapshotSegment);
    setCsnHandle(cmd.getResultHandle(), pSegment->getSnapshotCsn());
}
Example #4
0
void CmdInterpreter::visit(ProxyCmdCompleteBackup &cmd)
{
    DbHandle *pDbHandle = getDbHandle(cmd.getDbHandle());
    SharedDatabase pDb = pDbHandle->pDb;
    uint64_t paramVal = cmd.getLowerBoundCsn();
    TxnId lowerBoundCsn = isMAXU(paramVal) ? NULL_TXN_ID : TxnId(paramVal);
    volatile bool abortFlag = false;
    pDb->completeBackup(
        lowerBoundCsn,
        TxnId(cmd.getUpperBoundCsn()),
        (pExecHandle == NULL) ? abortFlag : pExecHandle->aborted);
}
Example #5
0
void CmdInterpreter::visit(ProxyCmdAlterSystemDeallocate &cmd)
{
    DbHandle *pDbHandle = getDbHandle(cmd.getDbHandle());
    SharedDatabase pDb = pDbHandle->pDb;
    if (!pDb->areSnapshotsEnabled()) {
        // Nothing to do if snapshots aren't enabled
        return;
    } else {
        uint64_t paramVal = cmd.getOldestLabelCsn();
        TxnId labelCsn = isMAXU(paramVal) ? NULL_TXN_ID : TxnId(paramVal);
        pDb->deallocateOldPages(labelCsn);
    }
}
Example #6
0
void CmdInterpreter::visit(ProxyCmdVersionIndexRoot &cmd)
{
    TxnHandle *pTxnHandle = getTxnHandle(cmd.getTxnHandle());
    SharedDatabase pDb = pTxnHandle->pDb;
    assert(pDb->areSnapshotsEnabled());

    SnapshotRandomAllocationSegment *pSnapshotSegment =
        SegmentFactory::dynamicCast<SnapshotRandomAllocationSegment *>(
            pTxnHandle->pSnapshotSegment);
    pSnapshotSegment->versionPage(
        PageId(cmd.getOldRootPageId()),
        PageId(cmd.getNewRootPageId()));
}
Example #7
0
extern "C" JNIEXPORT void JNICALL
Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphOpen(
    JNIEnv *pEnvInit, jclass, jlong hStreamGraph, jlong hTxn,
    jobject hJavaStreamMap, jobject hJavaErrorTarget)
{
    JniEnvRef pEnv(pEnvInit);
    try {
        CmdInterpreter::StreamGraphHandle &streamGraphHandle =
            CmdInterpreter::getStreamGraphHandleFromLong(hStreamGraph);
        CmdInterpreter::TxnHandle &txnHandle =
            CmdInterpreter::getTxnHandleFromLong(hTxn);
        // Provide runtime context for stream open(), which a scheduler may
        // defer until after our java caller returns: hence the global ref.
        if (streamGraphHandle.javaRuntimeContext) {
            // TODO jvs 13-May-2010:  Use a shared pointer for this
            // like we do with ErrorTarget, and track its JNI handle.
            pEnv->DeleteGlobalRef(streamGraphHandle.javaRuntimeContext);
            streamGraphHandle.javaRuntimeContext = NULL;
        }
        streamGraphHandle.javaRuntimeContext =
            pEnv->NewGlobalRef(hJavaStreamMap);
        streamGraphHandle.pExecStreamGraph->setTxn(txnHandle.pTxn);

        // When snapshots are enabled, switch the delegating segment so
        // the stream graph accesses the snapshot segment associated with
        // the current txn
        SharedDatabase pDb = txnHandle.pDb;
        if (pDb->areSnapshotsEnabled()) {
            DynamicDelegatingSegment *pSegment =
                SegmentFactory::dynamicCast<DynamicDelegatingSegment *>(
                    streamGraphHandle.pSegment);
            pSegment->setDelegatingSegment(
                WeakSegment(txnHandle.pSnapshotSegment));
            pSegment =
                SegmentFactory::dynamicCast<DynamicDelegatingSegment *>(
                    streamGraphHandle.pReadCommittedSegment);
            pSegment->setDelegatingSegment(
                WeakSegment(txnHandle.pReadCommittedSnapshotSegment));
        }
        streamGraphHandle.pExecStreamGraph->setErrorTarget(
            CmdInterpreter::newErrorTarget(hJavaErrorTarget));
        txnHandle.pResourceGovernor->requestResources(
            *(streamGraphHandle.pExecStreamGraph));
        streamGraphHandle.pExecStreamGraph->open();
        if (streamGraphHandle.pScheduler.unique()) {
            streamGraphHandle.pScheduler->start();
        }
    } catch (std::exception &ex) {
        pEnv.handleExcn(ex);
    }
}
Example #8
0
void CmdInterpreter::visit(ProxyCmdRestoreFromBackup &cmd)
{
    DbHandle *pDbHandle = getDbHandle(cmd.getDbHandle());
    SharedDatabase pDb = pDbHandle->pDb;
    uint64_t paramVal = cmd.getLowerBoundCsn();
    TxnId lowerBoundCsn = isMAXU(paramVal) ? NULL_TXN_ID : TxnId(paramVal);
    volatile bool abortFlag = false;
    pDb->restoreFromBackup(
        cmd.getBackupPathname(),
        cmd.getFileSize(),
        cmd.getCompressionProgram(),
        lowerBoundCsn,
        TxnId(cmd.getUpperBoundCsn()),
        (pExecHandle == NULL) ? abortFlag : pExecHandle->aborted);
}
Example #9
0
void CmdInterpreter::visit(ProxyCmdCreateExecutionStreamGraph &cmd)
{
#if 0
    struct mallinfo minfo = mallinfo();
    std::cout << "Number of allocated bytes before stream graph construction = "
        << minfo.uordblks << " bytes" << std::endl;
#endif
    TxnHandle *pTxnHandle = getTxnHandle(cmd.getTxnHandle());
    SharedDatabase pDb = pTxnHandle->pDb;
    SharedExecStreamGraph pGraph =
        ExecStreamGraph::newExecStreamGraph();
    pGraph->setTxn(pTxnHandle->pTxn);
    pGraph->setResourceGovernor(pTxnHandle->pResourceGovernor);
    std::auto_ptr<StreamGraphHandle> pStreamGraphHandle(
        new StreamGraphHandle());
    JniUtil::incrementHandleCount(
        STREAMGRAPHHANDLE_TRACE_TYPE_STR, pStreamGraphHandle.get());
    pStreamGraphHandle->javaRuntimeContext = NULL;
    pStreamGraphHandle->pTxnHandle = pTxnHandle;
    pStreamGraphHandle->pExecStreamGraph = pGraph;
    pStreamGraphHandle->pExecStreamFactory.reset(
        new ExecStreamFactory(
            pDb,
            pTxnHandle->pFtrsTableWriterFactory,
            pStreamGraphHandle.get()));
    // When snapshots are enabled, allocate DynamicDelegatingSegments for the
    // stream graph so if the stream graph is executed in different txns,
    // we can reset the delegate to whatever is the snapshot segment associated
    // with the current txn.
    if (pDb->areSnapshotsEnabled()) {
        pStreamGraphHandle->pSegment =
            pDb->getSegmentFactory()->newDynamicDelegatingSegment(
                pTxnHandle->pSnapshotSegment);
        pStreamGraphHandle->pReadCommittedSegment =
            pDb->getSegmentFactory()->newDynamicDelegatingSegment(
                pTxnHandle->pReadCommittedSnapshotSegment);
    }
    setStreamGraphHandle(
        cmd.getResultHandle(),
        pStreamGraphHandle.release());
}
Example #10
0
void CmdInterpreter::visit(ProxyCmdInitiateBackup &cmd)
{
    DbHandle *pDbHandle = getDbHandle(cmd.getDbHandle());
    SharedDatabase pDb = pDbHandle->pDb;
    uint64_t paramVal = cmd.getLowerBoundCsn();
    TxnId lowerBoundCsn = isMAXU(paramVal) ? NULL_TXN_ID : TxnId(paramVal);
    FileSize dataDeviceSize;

    volatile bool abortFlag = false;
    TxnId csn =
        pDb->initiateBackup(
            cmd.getBackupPathname(),
            cmd.isCheckSpaceRequirements(),
            FileSize(cmd.getSpacePadding()),
            lowerBoundCsn,
            cmd.getCompressionProgram(),
            dataDeviceSize,
            (pExecHandle == NULL) ? abortFlag : pExecHandle->aborted);
    cmd.setResultDataDeviceSize(dataDeviceSize);
    setCsnHandle(cmd.getResultHandle(), csn);
}
Example #11
0
void CmdInterpreter::visit(ProxyCmdRollback &cmd)
{
    TxnHandle *pTxnHandle = getTxnHandle(cmd.getTxnHandle());
    SharedDatabase pDb = pTxnHandle->pDb;

    // block checkpoints during this method
    bool txnBlocksCheckpoint = !pTxnHandle->readOnly && pDb->shouldForceTxns();
    SXMutexSharedGuard actionMutexGuard(
        pDb->getCheckpointThread()->getActionMutex());

    if (pDb->areSnapshotsEnabled()) {
        SnapshotRandomAllocationSegment *pSegment =
            SegmentFactory::dynamicCast<SnapshotRandomAllocationSegment *>(
                pTxnHandle->pSnapshotSegment);
        pSegment->rollbackChanges();
    }

    if (cmd.getSvptHandle()) {
        SavepointId svptId = getSavepointId(cmd.getSvptHandle());
        pTxnHandle->pTxn->rollback(&svptId);
    } else {
        pTxnHandle->pTxn->rollback();
        deleteAndNullify(pTxnHandle);
        if (txnBlocksCheckpoint && !pDb->areSnapshotsEnabled()) {
            // Implement rollback by simulating crash recovery,
            // reverting all pages modified by transaction.  No need
            // to do this when snapshots are in use because no permanent
            // pages were modified.
            pDb->recoverOnline();
        }
    }
}
Example #12
0
void CmdInterpreter::visit(ProxyCmdCommit &cmd)
{
    TxnHandle *pTxnHandle = getTxnHandle(cmd.getTxnHandle());
    SharedDatabase pDb = pTxnHandle->pDb;

    // block checkpoints during this method
    bool txnBlocksCheckpoint = !pTxnHandle->readOnly && pDb->shouldForceTxns();
    SXMutexSharedGuard actionMutexGuard(
        pDb->getCheckpointThread()->getActionMutex());

    if (pDb->areSnapshotsEnabled()) {
        // Commit the current txn, and start a new one so the versioned
        // pages that we're now going to commit will be marked with a txnId
        // corresponding to the time of the commit.  At present, those pages
        // are marked with a txnId corresponding to the start of the txn.
        pTxnHandle->pTxn->commit();
        pTxnHandle->pTxn = pDb->getTxnLog()->newLogicalTxn(pDb->getCache());
        SnapshotRandomAllocationSegment *pSnapshotSegment =
            SegmentFactory::dynamicCast<SnapshotRandomAllocationSegment *>(
                pTxnHandle->pSnapshotSegment);
        TxnId commitTxnId = pTxnHandle->pTxn->getTxnId();
        pSnapshotSegment->commitChanges(commitTxnId);

        // Flush pages associated with the snapshot segment.  Note that we
        // don't need to flush the underlying versioned segment first since
        // the snapshot pages are all new and therefore, are never logged.
        // Pages in the underlying versioned segment will be flushed in the
        // requestCheckpoint call further below.  Also note that the
        // checkpoint is not initiated through the dynamically cast segment
        // to ensure that the command is traced if tracing is turned on.
        if (txnBlocksCheckpoint) {
            pTxnHandle->pSnapshotSegment->checkpoint(CHECKPOINT_FLUSH_ALL);
        }
    }

    if (cmd.getSvptHandle()) {
        SavepointId svptId = getSavepointId(cmd.getSvptHandle());
        pTxnHandle->pTxn->commitSavepoint(svptId);
    } else {
        pTxnHandle->pTxn->commit();
        deleteAndNullify(pTxnHandle);
        if (txnBlocksCheckpoint) {
            // release the checkpoint lock acquired above
            actionMutexGuard.unlock();
            // force a checkpoint now to flush all data modified by transaction
            // to disk; wait for it to complete before reporting the
            // transaction as committed
            pDb->requestCheckpoint(CHECKPOINT_FLUSH_ALL, false);
        }
    }
}
Example #13
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformSharedMemory);
	Log.LoadLogSettingsDefaults();
	set_exception_handler();

	Log.Out(Logs::General, Logs::Status, "Shared Memory Loader Program");
	if(!EQEmuConfig::LoadConfig()) {
		Log.Out(Logs::General, Logs::Error, "Unable to load configuration file.");
		return 1;
	}

	auto Config = EQEmuConfig::get();

	SharedDatabase database;
	Log.Out(Logs::General, Logs::Status, "Connecting to database...");
	if(!database.Connect(Config->DatabaseHost.c_str(), Config->DatabaseUsername.c_str(),
		Config->DatabasePassword.c_str(), Config->DatabaseDB.c_str(), Config->DatabasePort)) {
		Log.Out(Logs::General, Logs::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 1;
	}

	/* Register Log System and Settings */
	database.LoadLogSettings(Log.log_settings);
	Log.StartFileLogs();

	database.LoadVariables();

	/* If we're running shared memory and hotfix has no custom name, we probably want to start from scratch... */
	std::string db_hotfix_name;
	if (database.GetVariable("hotfix_name", db_hotfix_name)) {
		if (!db_hotfix_name.empty() && strcasecmp("hotfix_", db_hotfix_name.c_str()) == 0) {
			Log.Out(Logs::General, Logs::Status, "Current hotfix in variables is the default %s, clearing out variable", db_hotfix_name.c_str());
			std::string query = StringFormat("UPDATE `variables` SET `value`='' WHERE (`varname`='hotfix_name')");
			database.QueryDatabase(query);
		}
	}

	std::string hotfix_name = "";
	bool load_all = true;
	bool load_items = false;
	bool load_factions = false;
	bool load_loot = false;
	bool load_skill_caps = false;
	bool load_spells = false;
	bool load_bd = false;
	if(argc > 1) {
		for(int i = 1; i < argc; ++i) {
			switch(argv[i][0]) {	
			case 'b':
				if(strcasecmp("base_data", argv[i]) == 0) {
					load_bd = true;
					load_all = false;
				}
				break;
	
			case 'i':
				if(strcasecmp("items", argv[i]) == 0) {
					load_items = true;
					load_all = false;
				}
				break;
	
			case 'f':
				if(strcasecmp("factions", argv[i]) == 0) {
					load_factions = true;
					load_all = false;
				}
				break;
	
			case 'l':
				if(strcasecmp("loot", argv[i]) == 0) {
					load_loot = true;
					load_all = false;
				}
				break;
	
			case 's':
				if(strcasecmp("skill_caps", argv[i]) == 0) {
					load_skill_caps = true;
					load_all = false;
				} else if(strcasecmp("spells", argv[i]) == 0) {
					load_spells = true;
					load_all = false;
				}
				break;
			case '-': {
				auto split = SplitString(argv[i], '=');
				if(split.size() >= 2) {
					auto command = split[0];
					auto argument = split[1];
					if(strcasecmp("-hotfix", command.c_str()) == 0) {
						hotfix_name = argument;
						load_all = true;
					}
				}
				break;
			}
			}
		}
	}

	if(hotfix_name.length() > 0) {
		Log.Out(Logs::General, Logs::Status, "Writing data for hotfix '%s'", hotfix_name.c_str());
	}
	
	if(load_all || load_items) {
		Log.Out(Logs::General, Logs::Status, "Loading items...");
		try {
			LoadItems(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_factions) {
		Log.Out(Logs::General, Logs::Status, "Loading factions...");
		try {
			LoadFactions(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_loot) {
		Log.Out(Logs::General, Logs::Status, "Loading loot...");
		try {
			LoadLoot(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_skill_caps) {
		Log.Out(Logs::General, Logs::Status, "Loading skill caps...");
		try {
			LoadSkillCaps(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_spells) {
		Log.Out(Logs::General, Logs::Status, "Loading spells...");
		try {
			LoadSpells(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_bd) {
		Log.Out(Logs::General, Logs::Status, "Loading base data...");
		try {
			LoadBaseData(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	Log.CloseFileLogs();
	return 0;
}
Example #14
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformSharedMemory);
	Log.LoadLogSettingsDefaults();
	set_exception_handler();

	Log.Out(Logs::General, Logs::Status, "Shared Memory Loader Program");
	if(!EQEmuConfig::LoadConfig()) {
		Log.Out(Logs::General, Logs::Error, "Unable to load configuration file.");
		return 1;
	}

	const EQEmuConfig *config = EQEmuConfig::get();

	SharedDatabase database;
	Log.Out(Logs::General, Logs::Status, "Connecting to database...");
	if(!database.Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(),
		config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) {
		Log.Out(Logs::General, Logs::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 1;
	}

	/* Register Log System and Settings */
	database.LoadLogSettings(Log.log_settings);
	Log.StartFileLogs();

	bool load_all = true;
	bool load_items = false;
	bool load_factions = false;
	bool load_loot = false;
	bool load_skill_caps = false;
	bool load_spells = false;
	bool load_bd = false;
	if(argc > 1) {
		load_all = false;

		for(int i = 1; i < argc; ++i) {
			switch(argv[i][0]) {
			case 'a':
				if(strcasecmp("all", argv[i]) == 0) {
					load_all = true;
				}
				break;

			case 'b':
				if(strcasecmp("base_data", argv[i]) == 0) {
					load_bd = true;
				}
				break;

			case 'i':
				if(strcasecmp("items", argv[i]) == 0) {
					load_items = true;
				}
				break;

			case 'f':
				if(strcasecmp("factions", argv[i]) == 0) {
					load_factions = true;
				}
				break;

			case 'l':
				if(strcasecmp("loot", argv[i]) == 0) {
					load_loot = true;
				}
				break;

			case 's':
				if(strcasecmp("skill_caps", argv[i]) == 0) {
					load_skill_caps = true;
				} else if(strcasecmp("spells", argv[i]) == 0) {
					load_spells = true;
				}
				break;
			}
		}
	}

	if(load_all || load_items) {
		Log.Out(Logs::General, Logs::Status, "Loading items...");
		try {
			LoadItems(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_factions) {
		Log.Out(Logs::General, Logs::Status, "Loading factions...");
		try {
			LoadFactions(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_loot) {
		Log.Out(Logs::General, Logs::Status, "Loading loot...");
		try {
			LoadLoot(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_skill_caps) {
		Log.Out(Logs::General, Logs::Status, "Loading skill caps...");
		try {
			LoadSkillCaps(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_spells) {
		Log.Out(Logs::General, Logs::Status, "Loading spells...");
		try {
			LoadSpells(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_bd) {
		Log.Out(Logs::General, Logs::Status, "Loading base data...");
		try {
			LoadBaseData(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	Log.CloseFileLogs();

	return 0;
}
Example #15
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformSharedMemory);
	set_exception_handler();

	LogFile->write(EQEMuLog::Status, "Shared Memory Loader Program");
	if(!EQEmuConfig::LoadConfig()) {
		LogFile->write(EQEMuLog::Error, "Unable to load configuration file.");
		return 0;
	}

	const EQEmuConfig *config = EQEmuConfig::get();
	if(!load_log_settings(config->LogSettingsFile.c_str())) {
		LogFile->write(EQEMuLog::Error, "Warning: unable to read %s.", config->LogSettingsFile.c_str());
	}

	SharedDatabase database;
	LogFile->write(EQEMuLog::Status, "Connecting to database...");
	if(!database.Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(),
		config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) {
		LogFile->write(EQEMuLog::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 0;
	}

	bool load_all = true;
	bool load_items = true;
	bool load_factions = true;
	bool load_loot = true;
	bool load_skill_caps = true;
	bool load_spells = true;
	if(argc > 1) {
		load_all = false;
		load_items = false;
		load_factions = false;
		load_loot = false;
		load_skill_caps = false;
		load_spells = false;

		for(int i = 1; i < argc; ++i) {
			switch(argv[i][0]) {
			case 'a':
				if(strcasecmp("all", argv[i]) == 0) {
					load_all = true;
				}
				break;

			case 'i':
				if(strcasecmp("items", argv[i]) == 0) {
					load_items = true;
				}
				break;

			case 'f':
				if(strcasecmp("factions", argv[i]) == 0) {
					load_factions = true;
				}
				break;

			case 'l':
				if(strcasecmp("loot", argv[i]) == 0) {
					load_loot = true;
				}
				break;

			case 's':
				if(strcasecmp("skill_caps", argv[i]) == 0) {
					load_skill_caps = true;
				} else if(strcasecmp("spells", argv[i]) == 0) {
					load_spells = true;
				}
				break;
			}
		}
	}

	if(load_all || load_items) {
		LogFile->write(EQEMuLog::Status, "Loading items...");
		try {
			LoadItems(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	if(load_all || load_factions) {
		LogFile->write(EQEMuLog::Status, "Loading factions...");
		try {
			LoadFactions(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	if(load_all || load_loot) {
		LogFile->write(EQEMuLog::Status, "Loading loot...");
		try {
			LoadLoot(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	if(load_all || load_skill_caps) {
		LogFile->write(EQEMuLog::Status, "Loading skill caps...");
		try {
			LoadSkillCaps(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	if(load_all || load_spells) {
		LogFile->write(EQEMuLog::Status, "Loading spells...");
		try {
			LoadSpells(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	return 0;
}
Example #16
0
void CmdInterpreter::visit(ProxyCmdOpenDatabase &cmd)
{
    ConfigMap configMap;

    SharedProxyDatabaseParam pParam = cmd.getParams();
    for (; pParam; ++pParam) {
        configMap.setStringParam(pParam->getName(), pParam->getValue());
    }

    CacheParams cacheParams;
    cacheParams.readConfig(configMap);
    SharedCache pCache = Cache::newCache(cacheParams);

    JniUtilParams jniUtilParams;
    jniUtilParams.readConfig(configMap);
    JniUtil::configure(jniUtilParams);

    DeviceMode openMode = cmd.isCreateDatabase()
        ? DeviceMode::createNew
        : DeviceMode::load;

    std::auto_ptr<DbHandle> pDbHandle(newDbHandle());
    JniUtil::incrementHandleCount(DBHANDLE_TRACE_TYPE_STR, pDbHandle.get());

    JavaTraceTarget *pJavaTraceTarget = newTraceTarget();
    pDbHandle->pTraceTarget.reset(pJavaTraceTarget);
    // on a fatal error, echo the backtrace to the log file:
    AutoBacktrace::setTraceTarget(pDbHandle->pTraceTarget);

    SharedDatabase pDb;
    try {
        pDb = Database::newDatabase(
            pCache,
            configMap,
            openMode,
            pDbHandle->pTraceTarget,
            SharedPseudoUuidGenerator(new JniPseudoUuidGenerator()));
    } catch (...) {
        AutoBacktrace::setTraceTarget();
        throw;
    }

    pDbHandle->pDb = pDb;

    ExecStreamResourceKnobs knobSettings;
    knobSettings.cacheReservePercentage =
        configMap.getIntParam("cacheReservePercentage");
    knobSettings.expectedConcurrentStatements =
        configMap.getIntParam("expectedConcurrentStatements");

    ExecStreamResourceQuantity resourcesAvailable;
    resourcesAvailable.nCachePages = pCache->getMaxLockedPages();

    pDbHandle->pResourceGovernor =
        SharedExecStreamGovernor(
            new SimpleExecStreamGovernor(
                knobSettings, resourcesAvailable,
                pDbHandle->pTraceTarget,
                "xo.resourceGovernor"));

    if (pDb->isRecoveryRequired()) {
        SegmentAccessor scratchAccessor =
            pDb->getSegmentFactory()->newScratchSegment(pDb->getCache());
        FtrsTableWriterFactory recoveryFactory(
            pDb,
            pDb->getCache(),
            pDb->getTypeFactory(),
            scratchAccessor);
        pDb->recover(recoveryFactory);
        cmd.setResultRecoveryRequired(true);
    } else {
        cmd.setResultRecoveryRequired(false);
    }
    pDbHandle->statsTimer.setTarget(*pJavaTraceTarget);
    pDbHandle->statsTimer.addSource(pDb);
    pDbHandle->statsTimer.addSource(pDbHandle->pResourceGovernor);
    pDbHandle->statsTimer.start();

    // Cache initialization may have been unable to allocate the requested
    // number of pages -- check for this case and report it in the log.
    if (pCache->getMaxAllocatedPageCount() != cacheParams.nMemPagesMax
        || pCache->getAllocatedPageCount() != cacheParams.nMemPagesInit)
    {
        FENNEL_DELEGATE_TRACE(
            TRACE_WARNING,
            pDb,
            "Unable to allocate "
            << cacheParams.nMemPagesInit
            << " (of "
            << cacheParams.nMemPagesMax
            << " max) cache pages; allocated "
            << pCache->getAllocatedPageCount()
            << " cache pages.");
    }

    setDbHandle(cmd.getResultHandle(), pDbHandle.release());
}
Example #17
0
void CmdInterpreter::visit(ProxyCmdAbandonBackup &cmd)
{
    DbHandle *pDbHandle = getDbHandle(cmd.getDbHandle());
    SharedDatabase pDb = pDbHandle->pDb;
    pDb->abortBackup();
}
Example #18
0
void CmdInterpreter::beginTxn(ProxyBeginTxnCmd &cmd, bool readOnly, TxnId csn)
{
    assert(readOnly || csn == NULL_TXN_ID);

    // block checkpoints during this method
    DbHandle *pDbHandle = getDbHandle(cmd.getDbHandle());
    SharedDatabase pDb = pDbHandle->pDb;

    SXMutexSharedGuard actionMutexGuard(
        pDb->getCheckpointThread()->getActionMutex());

    std::auto_ptr<TxnHandle> pTxnHandle(newTxnHandle());
    JniUtil::incrementHandleCount(TXNHANDLE_TRACE_TYPE_STR, pTxnHandle.get());
    pTxnHandle->pDb = pDb;
    pTxnHandle->readOnly = readOnly;
    // TODO:  CacheAccessor factory
    pTxnHandle->pTxn = pDb->getTxnLog()->newLogicalTxn(pDb->getCache());
    pTxnHandle->pResourceGovernor = pDbHandle->pResourceGovernor;

    // NOTE:  use a null scratchAccessor; individual ExecStreamGraphs
    // will have their own
    SegmentAccessor scratchAccessor;

    pTxnHandle->pFtrsTableWriterFactory = SharedFtrsTableWriterFactory(
        new FtrsTableWriterFactory(
            pDb,
            pDb->getCache(),
            pDb->getTypeFactory(),
            scratchAccessor));

    // If snapshots are enabled, set up 2 snapshot segments -- one of which
    // only reads committed data.  This will be used for streams that need to
    // read a snapshot of the data before other portions of the stream graph
    // have modified the segment.
    if (pDb->areSnapshotsEnabled()) {
        if (csn == NULL_TXN_ID) {
            csn = pTxnHandle->pTxn->getTxnId();
        }
        pTxnHandle->pSnapshotSegment =
            pDb->getSegmentFactory()->newSnapshotRandomAllocationSegment(
                pDb->getDataSegment(),
                pDb->getDataSegment(),
                csn,
                false);
        pTxnHandle->pReadCommittedSnapshotSegment =
            pDb->getSegmentFactory()->newSnapshotRandomAllocationSegment(
                pDb->getDataSegment(),
                pDb->getDataSegment(),
                csn,
                true);
    } else {
        assert(csn == NULL_TXN_ID);
    }

    setTxnHandle(cmd.getResultHandle(), pTxnHandle.release());
}
Example #19
0
void CmdInterpreter::visit(ProxyCmdGetLastCommittedTxnId &cmd)
{
    DbHandle *pDbHandle = getDbHandle(cmd.getDbHandle());
    SharedDatabase pDb = pDbHandle->pDb;
    setCsnHandle(cmd.getResultHandle(), pDb->getLastCommittedTxnId());
}