Beispiel #1
0
int delete_variable(variable* p)
{
	if(p==NULL) return 0;
	delete_variable(p->next);
	delete_qualifier(p->qualifiers);
	delete_curve(p->curves);
	delete_drange(p->dranges);
	delete_location(p->location_data);
	delete_orientation(p->orientation_data);
	free(p->length);
	free(p->kind);
	free(p->name);
	free(p->qualifier);
	free(p->id);
	free(p->range_min);
	free(p->range_max);
	free(p->default_value);
	free(p->precision);
	free(p->units);
	free(p->accuracy);
	free(p->scale_factor);
	free(p->scale_units);
	free(p->format);
	free(p->description);
	free(p->interface_name);
	free(p->interface_id);
	free(p->r_low);
	free(p->r_high);
	free(p->y_low);
	free(p->y_high);
	free(p->invalid_value);
	free(p);
	return 1;
}
Result PessimisticTxnManager::CommitTransaction() {
  LOG_TRACE("Committing peloton txn : %lu ", current_txn->GetTransactionId());

  auto &manager = catalog::Manager::GetInstance();

  auto &rw_set = current_txn->GetRWSet();

  //*****************************************************
  // we can optimize read-only transaction.
  if (current_txn->IsReadOnly() == true) {
    // validate read set.
    for (auto &tile_group_entry : rw_set) {
      oid_t tile_group_id = tile_group_entry.first;
      auto tile_group = manager.GetTileGroup(tile_group_id);
      auto tile_group_header = tile_group->GetHeader();
      for (auto &tuple_entry : tile_group_entry.second) {
        auto tuple_slot = tuple_entry.first;
        // if this tuple is not newly inserted.
        if (tuple_entry.second == RW_TYPE_READ) {
          // Release read locks
          if (pessimistic_released_rdlock.find(tile_group_id) ==
                  pessimistic_released_rdlock.end() ||
              pessimistic_released_rdlock[tile_group_id].find(tuple_slot) ==
                  pessimistic_released_rdlock[tile_group_id].end()) {
            ReleaseReadLock(tile_group_header, tuple_slot);
            pessimistic_released_rdlock[tile_group_id].insert(tuple_slot);
          }
        } else {
          assert(tuple_entry.second == RW_TYPE_INS_DEL);
        }
      }
    }
    // is it always true???
    Result ret = current_txn->GetResult();
    EndTransaction();
    return ret;
  }
  //*****************************************************

  // generate transaction id.
  cid_t end_commit_id = GetNextCommitId();

  auto &log_manager = logging::LogManager::GetInstance();
  log_manager.LogBeginTransaction(end_commit_id);

  // install everything.
  for (auto &tile_group_entry : rw_set) {
    oid_t tile_group_id = tile_group_entry.first;
    auto tile_group = manager.GetTileGroup(tile_group_id);
    auto tile_group_header = tile_group->GetHeader();
    for (auto &tuple_entry : tile_group_entry.second) {
      auto tuple_slot = tuple_entry.first;
      if (tuple_entry.second == RW_TYPE_READ) {
        // Release read locks
        if (pessimistic_released_rdlock.find(tile_group_id) ==
                pessimistic_released_rdlock.end() ||
            pessimistic_released_rdlock[tile_group_id].find(tuple_slot) ==
                pessimistic_released_rdlock[tile_group_id].end()) {
          ReleaseReadLock(tile_group_header, tuple_slot);
          pessimistic_released_rdlock[tile_group_id].insert(tuple_slot);
        }
      } else if (tuple_entry.second == RW_TYPE_UPDATE) {
        // we must guarantee that, at any time point, only one version is
        // visible.
        ItemPointer new_version =
            tile_group_header->GetNextItemPointer(tuple_slot);
        ItemPointer old_version(tile_group_id, tuple_slot);

        // logging.
        log_manager.LogUpdate(current_txn, end_commit_id, old_version,
                              new_version);

        auto new_tile_group_header =
            manager.GetTileGroup(new_version.block)->GetHeader();
        
        new_tile_group_header->SetEndCommitId(new_version.offset, MAX_CID);
        new_tile_group_header->SetBeginCommitId(new_version.offset,
                                                end_commit_id);

        COMPILER_MEMORY_FENCE;

        tile_group_header->SetEndCommitId(tuple_slot, end_commit_id);
        
        COMPILER_MEMORY_FENCE;

        new_tile_group_header->SetTransactionId(new_version.offset,
                                                INITIAL_TXN_ID);
        tile_group_header->SetTransactionId(tuple_slot, INITIAL_TXN_ID);

      } else if (tuple_entry.second == RW_TYPE_DELETE) {
        ItemPointer new_version =
            tile_group_header->GetNextItemPointer(tuple_slot);
        ItemPointer delete_location(tile_group_id, tuple_slot);
        
        // logging.
        log_manager.LogDelete(end_commit_id, delete_location);

        // we do not change begin cid for old tuple.
        auto new_tile_group_header =
            manager.GetTileGroup(new_version.block)->GetHeader();

        new_tile_group_header->SetEndCommitId(new_version.offset, MAX_CID);
        new_tile_group_header->SetBeginCommitId(new_version.offset,
                                                end_commit_id);
        
        COMPILER_MEMORY_FENCE;

        tile_group_header->SetEndCommitId(tuple_slot, end_commit_id);
        
        COMPILER_MEMORY_FENCE;

        new_tile_group_header->SetTransactionId(new_version.offset,
                                                INVALID_TXN_ID);
        tile_group_header->SetTransactionId(tuple_slot, INITIAL_TXN_ID);

      } else if (tuple_entry.second == RW_TYPE_INSERT) {
        assert(tile_group_header->GetTransactionId(tuple_slot) ==
               current_txn->GetTransactionId());
        // set the begin commit id to persist insert
        ItemPointer insert_location(tile_group_id, tuple_slot);
        log_manager.LogInsert(current_txn, end_commit_id, insert_location);

        tile_group_header->SetEndCommitId(tuple_slot, MAX_CID);
        tile_group_header->SetBeginCommitId(tuple_slot, end_commit_id);

        COMPILER_MEMORY_FENCE;

        tile_group_header->SetTransactionId(tuple_slot, INITIAL_TXN_ID);

      } else if (tuple_entry.second == RW_TYPE_INS_DEL) {
        assert(tile_group_header->GetTransactionId(tuple_slot) ==
               current_txn->GetTransactionId());

        tile_group_header->SetEndCommitId(tuple_slot, MAX_CID);
        tile_group_header->SetBeginCommitId(tuple_slot, MAX_CID);

        COMPILER_MEMORY_FENCE;

        // set the begin commit id to persist insert
        tile_group_header->SetTransactionId(tuple_slot, INVALID_TXN_ID);
      }
    }
  }
  log_manager.LogCommitTransaction(end_commit_id);

  EndTransaction();

  pessimistic_released_rdlock.clear();

  return Result::RESULT_SUCCESS;
}
Beispiel #3
0
/**
 * @brief Delete the table tuples using the position list in the logical tile.
 *
 * If truncate is on, then it will truncate the table itself.
 * @return true on success, false otherwise.
 */
bool DeleteExecutor::DExecute() {
  assert(target_table_);

  // Retrieve next tile.
  const bool success = children_[0]->Execute();
  if (!success) {
    return false;
  }

  std::unique_ptr<LogicalTile> source_tile(children_[0]->GetOutput());

  storage::Tile *tile = source_tile->GetBaseTile(0);
  storage::TileGroup *tile_group = tile->GetTileGroup();

  auto &pos_lists = source_tile.get()->GetPositionLists();
  auto tile_group_id = tile_group->GetTileGroupId();
  auto transaction_ = executor_context_->GetTransaction();

  LOG_INFO("Source tile : %p Tuples : %lu \n", source_tile.get(),
           source_tile->GetTupleCount());

  LOG_INFO("Transaction ID: %lu\n", transaction_->GetTransactionId());

  // Delete each tuple
  for (oid_t visible_tuple_id : *source_tile) {
    oid_t physical_tuple_id = pos_lists[0][visible_tuple_id];

    LOG_INFO("Visible Tuple id : %lu, Physical Tuple id : %lu \n",
             visible_tuple_id, physical_tuple_id);

    peloton::ItemPointer delete_location(tile_group_id, physical_tuple_id);

    // Logging
    {
      auto &log_manager = logging::LogManager::GetInstance();

      if (log_manager.IsInLoggingMode()) {
        auto logger = log_manager.GetBackendLogger();
        auto record = logger->GetTupleRecord(
            LOGRECORD_TYPE_TUPLE_DELETE, transaction_->GetTransactionId(),
            target_table_->GetOid(), INVALID_ITEMPOINTER, delete_location);

        logger->Log(record);
      }
    }

    // try to delete the tuple
    // this might fail due to a concurrent operation that has latched the tuple
    bool status = target_table_->DeleteTuple(transaction_, delete_location);

    if (status == false) {
      LOG_INFO("Fail to delete. Set txn failure");
      transaction_->SetResult(peloton::Result::RESULT_FAILURE);
      return false;
    }

    executor_context_->num_processed += 1;  // deleted one
    transaction_->RecordDelete(delete_location);
  }

  return true;
}
Beispiel #4
0
variable* merge_variables(variable* a,variable* b)
{
	if(a==NULL) return b;
	if(b==NULL) return a;
	/* The else if blocks are required to prevent a possible memory leak occuring when a attribute
	 in the xTEDS is specified multiple times, this isn't really enforceable in the xTEDS schema
	 unless an exhaustive list of all permutations of attribute orders was specified in the grammar*/
	if(a->length==NULL) a->length = b->length;
	  else if(b->length!=NULL) free(b->length);
	
	if(a->kind==NULL) a->kind = b->kind;
	  else if(b->kind!=NULL) free(b->kind);
	
	if(a->name==NULL) a->name = b->name;
	  else if(b->name!=NULL) free(b->name);
	
	if(a->qualifier==NULL) a->qualifier = b->qualifier;
	  else if(b->qualifier!=NULL) free(b->qualifier);
	
	if(a->id==NULL) a->id = b->id;
	  else if(b->id!=NULL) free(b->id);
	
	if(a->range_min==NULL) a->range_min = b->range_min;
	  else if(b->range_min!=NULL) free(b->range_min);
	
	if(a->range_max==NULL) a->range_max = b->range_max;
	  else if(b->range_max!=NULL) free(b->range_max);
	
	if(a->default_value==NULL) a->default_value = b->default_value;
	  else if(b->default_value!=NULL) free(b->default_value);
	
	if(a->precision==NULL) a->precision = b->precision;
	  else if(b->precision!=NULL) free(b->precision);
	
	if(a->units==NULL) a->units = b->units;
	  else if(b->units!=NULL) free(b->units);
	
	if(a->accuracy==NULL) a->accuracy = b->accuracy;
	  else if(b->accuracy!=NULL) free(b->accuracy);
	
	if(a->scale_factor==NULL) a->scale_factor = b->scale_factor;
	  else if(b->scale_factor!=NULL) free(b->scale_factor);
	
	if(a->scale_units==NULL) a->scale_units = b->scale_units;
	  else if(b->scale_units!=NULL) free(b->scale_units);
	
	if(a->format==NULL) a->format = b->format;
	  else if(b->format!=NULL) free(b->format);
	
	if(a->description==NULL) a->description = b->description;
	  else if(b->description!=NULL) free(b->description);
	
	if(a->qualifiers==NULL) a->qualifiers = b->qualifiers;
	  else if(b->qualifiers!=NULL) free(b->qualifiers);
	
	if(a->curves==NULL) a->curves = b->curves;
	  else if(b->curves!=NULL) delete_curve(b->curves);
	
	if(a->dranges==NULL) a->dranges = b->dranges;
	  else if(b->dranges!=NULL) delete_drange(b->dranges);
	
	if(a->location_data==NULL) a->location_data = b->location_data;
	  else if(b->location_data!=NULL) delete_location(b->location_data);
	
	if (a->r_low == NULL) a->r_low = b->r_low;
	  else if(b->r_low!=NULL) free(b->r_low);
	
	if (a->r_high == NULL) a->r_high = b->r_high;
	  else if(b->r_high!=NULL) free(b->r_high);
	
	if (a->y_low == NULL) a->y_low = b->y_low;
	  else if(b->y_low!=NULL) free(b->y_low);
	
	if (a->y_high == NULL) a->y_high = b->y_high;
	  else if(b->y_high!=NULL) free(b->y_high);
	
	if (a->invalid_value == NULL) a->invalid_value = b->invalid_value;
	  else if(b->invalid_value!=NULL) free(b->invalid_value);
	
	a->orientation_data = link_orientations(a->orientation_data,b->orientation_data);
	free(b);
	/*Keep a reference to this variable tree for VarInfoParser*/
	var_result = a;
	return a;
}