src/backend/storage/data_table.cpp
// this function is called when update/delete/insert is performed.
// this function first checks whether there's available slot.
// if yes, then directly return the available slot.
// in particular, if this is the last slot, a new tile group is created.
// if there's no available slot, then some other threads must be allocating a
// new tile group.
// we just wait until a new tuple slot in the newly allocated tile group is
// available.
this function is called when update/delete/insert is performed.
this function first checks whether there's available slot.
if yes, then directly return the available slot.
in particular, if this is the last slot, a new tile group is created.
if there's no available slot, then some other threads must be allocating a
new tile group.
we just wait until a new tuple slot in the newly allocated tile group is
available.
this function is called when update / delete / insert is performed . this function first checks whether there ' s available slot . if yes then directly return the available slot . in particular if this is the last slot a new tile group is created . if there ' s no available slot then some other threads must be allocating a new tile group . we just wait until a new tuple slot in the newly allocated tile group is available .
ItemPointer DataTable::GetEmptyTupleSlot(const storage::Tuple *tuple,
                                         bool check_constraint) {
  assert(tuple);
  if (check_constraint == true && CheckConstraints(tuple) == false) {
    return INVALID_ITEMPOINTER;
  }
  auto &gc_manager = gc::GCManagerFactory::GetInstance();
  auto free_item_pointer = gc_manager.ReturnFreeSlot(this->table_oid);
  if (free_item_pointer.IsNull() == false) {
    return free_item_pointer;
  }
  std::shared_ptr<storage::TileGroup> tile_group;
  oid_t tuple_slot = INVALID_OID;
  oid_t tile_group_id = INVALID_OID;
  while (true) {
    tile_group = GetTileGroup(tile_group_count_ - 1);
    tuple_slot = tile_group->InsertTuple(tuple);
    if (tuple_slot != INVALID_OID) {
      tile_group_id = tile_group->GetTileGroupId();
      LOG_INFO("%s", GetInfo().c_str());
      break;
    }
  }
  if (tuple_slot == tile_group->GetAllocatedTupleCount() - 1) {
    AddDefaultTileGroup();
  }
  LOG_TRACE("tile group count: %lu, tile group id: %u, address: %p",
            tile_group_count_.load(), tile_group->GetTileGroupId(), tile_group.get());
  ItemPointer location(tile_group_id, tuple_slot);
  return location;
}
ItemPointer DataTable :: GetEmptyTupleSlot ( const storage :: Tuple * tuple , bool check_constraint ) { assert ( tuple ) ; if ( check_constraint == true && CheckConstraints ( tuple ) == false ) { return INVALID_ITEMPOINTER ; } auto & gc_manager = gc :: GCManagerFactory :: GetInstance ( ) ; auto free_item_pointer = gc_manager . ReturnFreeSlot ( this -> table_oid ) ; if ( free_item_pointer . IsNull ( ) == false ) { return free_item_pointer ; } std :: shared_ptr < storage :: TileGroup > tile_group ; oid_t tuple_slot = INVALID_OID ; oid_t tile_group_id = INVALID_OID ; while ( true ) { tile_group = GetTileGroup ( tile_group_count_ - 1 ) ; tuple_slot = tile_group -> InsertTuple ( tuple ) ; if ( tuple_slot != INVALID_OID ) { tile_group_id = tile_group -> GetTileGroupId ( ) ; LOG_INFO ( " " , GetInfo ( ) . c_str ( ) ) ; break ; } } if ( tuple_slot == tile_group -> GetAllocatedTupleCount ( ) - 1 ) { AddDefaultTileGroup ( ) ; } LOG_TRACE ( " " , tile_group_count_ . load ( ) , tile_group -> GetTileGroupId ( ) , tile_group . get ( ) ) ; ItemPointer location ( tile_group_id , tuple_slot ) ; return location ; }
this function is called when update/delete/insert is performed.
this function is called when update / delete / insert is performed .
//=============== garbage collection================== // check if there are recycled tuple slots //==================================================== // get valid tuple. // get the last tile group. // now we have already obtained a new tuple slot. // if this is the last tuple slot we can get // then create a new tile group // Set tuple location