bool DataTable::InsertInSecondaryIndexes(const AbstractTuple *tuple, const TargetList *targets_ptr, ItemPointer *index_entry_ptr) { int index_count = GetIndexCount(); // Transaform the target list into a hash set // when attempting to perform insertion to a secondary index, // we must check whether the updated column is a secondary index column. // insertion happens only if the updated column is a secondary index column. std::unordered_set<oid_t> targets_set; for (auto target : *targets_ptr) { targets_set.insert(target.first); } // Check existence for primary/unique indexes // Since this is NOT protected by a lock, concurrent insert may happen. for (int index_itr = index_count - 1; index_itr >= 0; --index_itr) { auto index = GetIndex(index_itr); auto index_schema = index->GetKeySchema(); auto indexed_columns = index_schema->GetIndexedColumns(); if (index->GetIndexType() == INDEX_CONSTRAINT_TYPE_PRIMARY_KEY) { continue; } // Check if we need to update the secondary index bool updated = false; for (auto col : indexed_columns) { if (targets_set.find(col) != targets_set.end()) { updated = true; break; } } // If attributes on key are not updated, skip the index update if (updated == false) { continue; } // Key attributes are updated, insert a new entry in all secondary index std::unique_ptr<storage::Tuple> key(new storage::Tuple(index_schema, true)); key->SetFromTuple(tuple, indexed_columns, index->GetPool()); switch (index->GetIndexType()) { case INDEX_CONSTRAINT_TYPE_PRIMARY_KEY: break; case INDEX_CONSTRAINT_TYPE_UNIQUE: break; case INDEX_CONSTRAINT_TYPE_DEFAULT: default: index->InsertEntry(key.get(), index_entry_ptr); break; } LOG_TRACE("Index constraint check on %s passed.", index->GetName().c_str()); } return true; }
bool DataTable::InsertInSecondaryIndexes(const storage::Tuple *tuple, ItemPointer location) { int index_count = GetIndexCount(); // (A) Check existence for primary/unique indexes // FIXME Since this is NOT protected by a lock, concurrent insert may happen. for (int index_itr = index_count - 1; index_itr >= 0; --index_itr) { auto index = GetIndex(index_itr); auto index_schema = index->GetKeySchema(); auto indexed_columns = index_schema->GetIndexedColumns(); std::unique_ptr<storage::Tuple> key(new storage::Tuple(index_schema, true)); key->SetFromTuple(tuple, indexed_columns, index->GetPool()); switch (index->GetIndexType()) { case INDEX_CONSTRAINT_TYPE_PRIMARY_KEY: break; case INDEX_CONSTRAINT_TYPE_UNIQUE: { // if in this index there has been a visible or uncommitted // <key, location> pair, this constraint is violated index->InsertEntry(key.get(), location); } break; case INDEX_CONSTRAINT_TYPE_DEFAULT: default: index->InsertEntry(key.get(), location); break; } LOG_TRACE("Index constraint check on %s passed.", index->GetName().c_str()); } return true; }
//Draw single object, can loop soon //TODO: make drawall //TODO: make seperate from gob void RenderEngine::DrawIndexedObject(GraphicalObject * gob ) { //TODO: set attribs elsewhere RenderInfo * renderInfo = gob->GetRenderInfoPtr(); //TODO: assign offsets elsewhere //static unsigned int colOffset = ColorVertex::GetColorOffset(); //static unsigned int posOffset = ColorVertex::GetPositionOffset(); //static GLint numPosits = 3; //static GLint numCols = 3; //glEnableVertexAttribArray(m_positionAttrib); //glEnableVertexAttribArray(m_colorAttrib); //glBindBuffer(GL_ARRAY_BUFFER, renderInfo->m_vertBufferID); //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderInfo->m_indBufferID); //SetAttributes(gob, &(renderInfo->m_vertexFormat), renderInfo->m_stride); //glVertexAttribPointer(m_positionAttrib, numPosits, GL_FLOAT, GL_FALSE, renderInfo->m_stride, (void*)posOffset); // glVertexAttribPointer(m_colorAttrib, numCols, GL_FLOAT, GL_FALSE, renderInfo->m_stride, (void*)colOffset); //----------------------------HANDLE ELSEWHERE--------------------------- //glUniform3fv(15, 1, (GLfloat*)gob->GetTint()); //glUniformMatrix4fv(16, 1, GL_FALSE, &screenMat[0][0]); //----------------------------------------------------------------------- //GLuint * buffData = new GLuint[renderInfo->m_indexSizeBytes]{ 0 }; //GLuint * buffDataPtr = buffData; //glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, renderInfo->m_indexOffsetBytes, renderInfo->m_indexSizeBytes, buffData); //for (int i = 0; i < renderInfo->m_indexSizeBytes; i++) //{ // //printf("Element %d [%u]\n", i, *buffDataPtr); // GameLogger::Log(LogMsgType::Debug, "Element %d: [%u]", i, *buffDataPtr); // ++buffDataPtr; //} //delete[] buffData; //GLfloat * buffData = new GLfloat[renderInfo->m_numVerts * 6]{ 0 }; //GLfloat * buffDataPtr = buffData; //glGetBufferSubData(GL_ARRAY_BUFFER, renderInfo->m_vertOffset*sizeof(GLfloat)*6, renderInfo->m_numVerts * sizeof(GLfloat) * 6, buffData); //for (int i = 0; i < renderInfo->m_numVerts * 6; i++) //{ // //printf("Element %d [%u]\n", i, *buffDataPtr); // GameLogger::Log(LogMsgType::Debug, "Element %d: [%f]", i, *buffDataPtr); // ++buffDataPtr; //} //delete[] buffData; glDrawElementsBaseVertex(renderInfo->m_draw_mode, renderInfo->m_numIndices, GetIndexType(renderInfo->m_isb),(void *)renderInfo->m_indexOffsetBytes,renderInfo->m_vertOffset); }
/** * @brief Insert a tuple into all indexes. If index is primary/unique, * check visibility of existing * index entries. * @warning This still doesn't guarantee serializability. * * @returns True on success, false if a visible entry exists (in case of *primary/unique). */ bool DataTable::InsertInIndexes(const storage::Tuple *tuple, ItemPointer location) { int index_count = GetIndexCount(); auto &transaction_manager = concurrency::TransactionManagerFactory::GetInstance(); std::function<bool(const ItemPointer &)> fn = std::bind(&concurrency::TransactionManager::IsOccupied, &transaction_manager, std::placeholders::_1); // (A) Check existence for primary/unique indexes // FIXME Since this is NOT protected by a lock, concurrent insert may happen. for (int index_itr = index_count - 1; index_itr >= 0; --index_itr) { auto index = GetIndex(index_itr); auto index_schema = index->GetKeySchema(); auto indexed_columns = index_schema->GetIndexedColumns(); std::unique_ptr<storage::Tuple> key(new storage::Tuple(index_schema, true)); key->SetFromTuple(tuple, indexed_columns, index->GetPool()); switch (index->GetIndexType()) { case INDEX_CONSTRAINT_TYPE_PRIMARY_KEY: case INDEX_CONSTRAINT_TYPE_UNIQUE: { // TODO: get unique tuple from primary index. // if in this index there has been a visible or uncommitted // <key, location> pair, this constraint is violated if (index->CondInsertEntry(key.get(), location, fn) == false) { return false; } } break; case INDEX_CONSTRAINT_TYPE_DEFAULT: default: index->InsertEntry(key.get(), location); break; } LOG_TRACE("Index constraint check on %s passed.", index->GetName().c_str()); } return true; }
/** * @brief Insert a tuple into all indexes. If index is primary/unique, * check visibility of existing * index entries. * @warning This still doesn't guarantee serializability. * * @returns True on success, false if a visible entry exists (in case of *primary/unique). */ bool DataTable::InsertInIndexes(const storage::Tuple *tuple, ItemPointer location, concurrency::Transaction *transaction, ItemPointer **index_entry_ptr) { int index_count = GetIndexCount(); size_t active_indirection_array_id = number_of_tuples_ % ACTIVE_INDIRECTION_ARRAY_COUNT; size_t indirection_offset = INVALID_INDIRECTION_OFFSET; while (true) { auto active_indirection_array = active_indirection_arrays_[active_indirection_array_id]; indirection_offset = active_indirection_array->AllocateIndirection(); if (indirection_offset != INVALID_INDIRECTION_OFFSET) { *index_entry_ptr = active_indirection_array->GetIndirectionByOffset(indirection_offset); break; } } (*index_entry_ptr)->block = location.block; (*index_entry_ptr)->offset = location.offset; if (indirection_offset == INDIRECTION_ARRAY_MAX_SIZE - 1) { AddDefaultIndirectionArray(active_indirection_array_id); } auto &transaction_manager = concurrency::TransactionManagerFactory::GetInstance(); std::function<bool(const void *)> fn = std::bind(&concurrency::TransactionManager::IsOccupied, &transaction_manager, transaction, std::placeholders::_1); // Since this is NOT protected by a lock, concurrent insert may happen. bool res = true; int success_count = 0; for (int index_itr = index_count - 1; index_itr >= 0; --index_itr) { auto index = GetIndex(index_itr); auto index_schema = index->GetKeySchema(); auto indexed_columns = index_schema->GetIndexedColumns(); std::unique_ptr<storage::Tuple> key(new storage::Tuple(index_schema, true)); key->SetFromTuple(tuple, indexed_columns, index->GetPool()); switch (index->GetIndexType()) { case INDEX_CONSTRAINT_TYPE_PRIMARY_KEY: { // get unique tuple from primary index. // if in this index there has been a visible or uncommitted // <key, location> pair, this constraint is violated res = index->CondInsertEntry(key.get(), *index_entry_ptr, fn); } break; case INDEX_CONSTRAINT_TYPE_UNIQUE: { // get unique tuple from primary index. // if in this index there has been a visible or uncommitted // <key, location> pair, this constraint is violated // res = index->CondInsertEntry(key.get(), *index_entry_ptr, fn); } break; case INDEX_CONSTRAINT_TYPE_DEFAULT: default: index->InsertEntry(key.get(), *index_entry_ptr); break; } // Handle failure if (res == false) { // If some of the indexes have been inserted, // the pointer has a chance to be dereferenced by readers and it cannot be deleted *index_entry_ptr = nullptr; return false; } else { success_count += 1; } LOG_TRACE("Index constraint check on %s passed.", index->GetName().c_str()); } return true; }