storage::DataTable *TransactionTestsUtil::CreatePrimaryKeyUniqueKeyTable() { auto id_column = catalog::Column(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER), "id", true); id_column.AddConstraint(catalog::Constraint(CONSTRAINT_TYPE_NOTNULL, "not_null")); auto value_column = catalog::Column( VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER), "value", true); // Create the table catalog::Schema *table_schema = new catalog::Schema({id_column, value_column}); auto table_name = "TEST_TABLE"; size_t tuples_per_tilegroup = 100; auto table = storage::TableFactory::GetDataTable( INVALID_OID, INVALID_OID, table_schema, table_name, tuples_per_tilegroup, true, false); // Create primary index on the id column std::vector<oid_t> key_attrs = {0}; auto tuple_schema = table->GetSchema(); bool unique = false; auto key_schema = catalog::Schema::CopySchema(tuple_schema, key_attrs); key_schema->SetIndexedColumns(key_attrs); auto index_metadata = new index::IndexMetadata( "primary_btree_index", 1234, INDEX_TYPE_BTREE, INDEX_CONSTRAINT_TYPE_PRIMARY_KEY, tuple_schema, key_schema, unique); index::Index *pkey_index = index::IndexFactory::GetInstance(index_metadata); table->AddIndex(pkey_index); // Create unique index on the value column std::vector<oid_t> key_attrs2 = {1}; auto tuple_schema2 = table->GetSchema(); bool unique2 = false; auto key_schema2 = catalog::Schema::CopySchema(tuple_schema2, key_attrs2); key_schema2->SetIndexedColumns(key_attrs2); auto index_metadata2 = new index::IndexMetadata( "unique_btree_index", 1235, INDEX_TYPE_BTREE, INDEX_CONSTRAINT_TYPE_UNIQUE, tuple_schema2, key_schema2, unique2); index::Index *ukey_index = index::IndexFactory::GetInstance(index_metadata2); table->AddIndex(ukey_index); // Insert tuple auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); auto txn = txn_manager.BeginTransaction(); for (int i = 0; i < 10; i++) { ExecuteInsert(txn, table, i, i); } txn_manager.CommitTransaction(); return table; }
storage::DataTable *TransactionTestsUtil::CreateTable(int num_key, std::string table_name, oid_t database_id, oid_t relation_id, oid_t index_oid, bool need_primary_index) { auto id_column = catalog::Column(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER), "id", true); auto value_column = catalog::Column( VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER), "value", true); // Create the table catalog::Schema *table_schema = new catalog::Schema({id_column, value_column}); size_t tuples_per_tilegroup = 100; auto table = storage::TableFactory::GetDataTable( database_id, relation_id, table_schema, table_name, tuples_per_tilegroup, true, false); // Create index on the id column std::vector<oid_t> key_attrs = {0}; auto tuple_schema = table->GetSchema(); bool unique = false; auto key_schema = catalog::Schema::CopySchema(tuple_schema, key_attrs); key_schema->SetIndexedColumns(key_attrs); auto index_metadata = new index::IndexMetadata( "primary_btree_index", index_oid, INDEX_TYPE_BTREE, need_primary_index ? INDEX_CONSTRAINT_TYPE_PRIMARY_KEY : INDEX_CONSTRAINT_TYPE_DEFAULT, tuple_schema, key_schema, unique); index::Index *pkey_index = index::IndexFactory::GetInstance(index_metadata); table->AddIndex(pkey_index); // add this table to current database auto &manager = catalog::Manager::GetInstance(); storage::Database *db = manager.GetDatabaseWithOid(database_id); if (db != nullptr) { db->AddTable(table); } // Insert tuple auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); auto txn = txn_manager.BeginTransaction(); for (int i = 0; i < num_key; i++) { ExecuteInsert(txn, table, i, 0); } txn_manager.CommitTransaction(); return table; }
void CCommandAI::GiveAllowedCommand(const Command& c, bool fromSynced) { if (ExecuteStateCommand(c)) { return; } switch (c.id) { case CMD_SELFD: { if (owner->unitDef->canSelfD) { if (!(c.options & SHIFT_KEY) || commandQue.empty()) { if (owner->selfDCountdown != 0) { owner->selfDCountdown = 0; } else { owner->selfDCountdown = owner->unitDef->selfDCountdown*2+1; } } else { if (commandQue.back().id == CMD_SELFD) { commandQue.pop_back(); } else { commandQue.push_back(c); } } } return; } case CMD_SET_WANTED_MAX_SPEED: { if (CanSetMaxSpeed() && (commandQue.empty() || (commandQue.back().id != CMD_SET_WANTED_MAX_SPEED))) { // bail early, do not check for overlaps or queue cancelling commandQue.push_back(c); if (commandQue.size()==1 && !owner->beingBuilt) { SlowUpdate(); } } return; } case CMD_WAIT: { GiveWaitCommand(c); return; } case CMD_INSERT: { ExecuteInsert(c, fromSynced); return; } case CMD_REMOVE: { ExecuteRemove(c); return; } } // flush the queue for immediate commands if (!(c.options & SHIFT_KEY)) { if (!commandQue.empty()) { if ((commandQue.front().id == CMD_DGUN) || (commandQue.front().id == CMD_ATTACK) || (commandQue.front().id == CMD_AREA_ATTACK)) { owner->AttackUnit(0,true); } waitCommandsAI.ClearUnitQueue(owner, commandQue); commandQue.clear(); } inCommand=false; if(orderTarget){ DeleteDeathDependence(orderTarget); orderTarget=0; } } if (c.id == CMD_PATROL) { CCommandQueue::iterator ci = commandQue.begin(); for (; ci != commandQue.end() && ci->id != CMD_PATROL; ci++) { // just increment } if (ci == commandQue.end()) { if (commandQue.empty()) { Command c2; c2.id = CMD_PATROL; c2.params.push_back(owner->pos.x); c2.params.push_back(owner->pos.y); c2.params.push_back(owner->pos.z); c2.options = c.options; commandQue.push_back(c2); } else { do { ci--; if (ci->params.size() >= 3) { Command c2; c2.id = CMD_PATROL; c2.params = ci->params; c2.options = c.options; commandQue.push_back(c2); break; } else if (ci == commandQue.begin()) { Command c2; c2.id = CMD_PATROL; c2.params.push_back(owner->pos.x); c2.params.push_back(owner->pos.y); c2.params.push_back(owner->pos.z); c2.options = c.options; commandQue.push_back(c2); break; } } while (ci != commandQue.begin()); } } } // cancel duplicated commands bool first; if (CancelCommands(c, commandQue, first) > 0) { if (first) { Command stopCommand; stopCommand.id = CMD_STOP; commandQue.push_front(stopCommand); SlowUpdate(); } return; } // do not allow overlapping commands if (!GetOverlapQueued(c).empty()) { return; } if (c.id == CMD_ATTACK) { // avoid weaponless units moving to 0 distance when given attack order if (owner->weapons.empty() && (owner->unitDef->canKamikaze == false)) { Command c2; c2.id = CMD_STOP; commandQue.push_back(c2); return; } } commandQue.push_back(c); if (commandQue.size() == 1 && !owner->beingBuilt && !owner->stunned) { SlowUpdate(); } }
void CCommandAI::GiveAllowedCommand(const Command& c, bool fromSynced) { if (ExecuteStateCommand(c)) { return; } switch (c.GetID()) { case CMD_SELFD: { if (owner->unitDef->canSelfD) { if (!(c.options & SHIFT_KEY) || commandQue.empty()) { if (owner->selfDCountdown != 0) { owner->selfDCountdown = 0; } else { owner->selfDCountdown = owner->unitDef->selfDCountdown*2+1; } } else if (commandQue.back().GetID() == CMD_SELFD) { commandQue.pop_back(); } else { commandQue.push_back(c); } } return; } case CMD_SET_WANTED_MAX_SPEED: { if (CanSetMaxSpeed() && (commandQue.empty() || (commandQue.back().GetID() != CMD_SET_WANTED_MAX_SPEED))) { // bail early, do not check for overlaps or queue cancelling commandQue.push_back(c); if (commandQue.size()==1 && !owner->beingBuilt) { SlowUpdate(); } } return; } case CMD_WAIT: { GiveWaitCommand(c); return; } case CMD_INSERT: { ExecuteInsert(c, fromSynced); return; } case CMD_REMOVE: { ExecuteRemove(c); return; } } // flush the queue for immediate commands // NOTE: CMD_STOP can be a queued order (!) if (!(c.options & SHIFT_KEY)) { waitCommandsAI.ClearUnitQueue(owner, commandQue); ClearTargetLock((commandQue.empty())? Command(CMD_STOP): commandQue.front()); ClearCommandDependencies(); SetOrderTarget(NULL); // if c is an attack command, the actual order-target // gets set via ExecuteAttack (called from SlowUpdate // at the end of this function) commandQue.clear(); assert(commandQue.empty()); inCommand = false; } AddCommandDependency(c); if (c.GetID() == CMD_PATROL) { CCommandQueue::iterator ci = commandQue.begin(); for (; ci != commandQue.end() && ci->GetID() != CMD_PATROL; ++ci) { // just increment } if (ci == commandQue.end()) { if (commandQue.empty()) { Command c2(CMD_PATROL, c.options, owner->pos); commandQue.push_back(c2); } else { do { --ci; if (ci->params.size() >= 3) { Command c2(CMD_PATROL, c.options); c2.params = ci->params; commandQue.push_back(c2); break; } else if (ci == commandQue.begin()) { Command c2(CMD_PATROL, c.options, owner->pos); commandQue.push_back(c2); break; } } while (ci != commandQue.begin()); } } } // cancel duplicated commands bool first; if (CancelCommands(c, commandQue, first) > 0) { if (first) { Command stopCommand(CMD_STOP); commandQue.push_front(stopCommand); SlowUpdate(); } return; } // do not allow overlapping commands if (!GetOverlapQueued(c).empty()) { return; } if (c.GetID() == CMD_ATTACK) { // avoid weaponless units moving to 0 distance when given attack order if (owner->weapons.empty() && (!owner->unitDef->canKamikaze)) { Command c2(CMD_STOP); commandQue.push_back(c2); return; } } commandQue.push_back(c); if (commandQue.size() == 1 && !owner->beingBuilt && !owner->IsStunned()) { SlowUpdate(); } }
int InsertHostLimits(vector<string> * v){ char query[200]; char * fixedInsertStr; unsigned int len; char * cTemp; char * host; char * upper; char * lower; unsigned int hostID = 0; unsigned int id = 0; unsigned int lowerInt = 0; unsigned int upperInt = 0; int ret = 0; //For each host to measure in the vector for(unsigned int i=0; i < v->size(); i++){ string temp = v->at(i); cTemp = (char *)temp.c_str(); host = strtok_s(NULL, "||", &cTemp); if(host == NULL){ printf("InsertHostLimits: strtok_s() 1 failed\n"); v->clear(); return GENERIC_ERROR; } upper = strtok_s(NULL, "||", &cTemp); if(upper == NULL){ printf("InsertHostLimits: strtok_s() 2 failed\n"); v->clear(); return GENERIC_ERROR; } lower = strtok_s(NULL, "||", &cTemp); if(lower == NULL){ printf("InsertHostLimits: strtok_s() 3 failed\n"); v->clear(); return GENERIC_ERROR; } upperInt = atoi((const char *)upper); lowerInt = atoi((const char *)lower); // get hostID from host //ret = SelectHostIDByIP(host, &hostID); id = 0; fixedInsertStr = "SELECT id FROM HostControlLimits WHERE hostID = '%s' ORDER BY id DESC LIMIT 1"; len = sprintf_s(query, 200, fixedInsertStr, host); SelectSingleIntResult(SERVER, query, len, &id); if(id == 0) { fixedInsertStr = "INSERT INTO HostControlLimits VALUES(NULL,'%s',%u,%u)"; len = sprintf_s(query, 200, fixedInsertStr, host, upperInt, lowerInt); ret = ExecuteInsert(SERVER, query, len, &id); if(ret != GENERIC_SUCCESS){ v->clear(); return GENERIC_ERROR; } } } v->clear(); return GENERIC_SUCCESS; }