static void insert_locations (GtkTreeStore *store, GWeatherLocation *loc) { int i; if (gweather_location_get_level (loc) < GWEATHER_LOCATION_COUNTRY) { GWeatherLocation **children; children = gweather_location_get_children (loc); for (i = 0; children[i]; i++) insert_locations (store, children[i]); } else { GWeatherTimezone **zones; GtkTreeIter iter; zones = gweather_location_get_timezones (loc); if (zones[1]) { gtk_tree_store_append (store, &iter, NULL); gtk_tree_store_set (store, &iter, GWEATHER_TIMEZONE_MENU_NAME, gweather_location_get_name (loc), -1); for (i = 0; zones[i]; i++) { insert_location (store, zones[i], NULL, &iter); } } else if (zones[0]) { insert_location (store, zones[0], gweather_location_get_name (loc), NULL); } gweather_location_free_timezones (loc, zones); } }
void form_location_insert(char *input) { Location *location; Client *client; location = location_malloc(); location->id = insert_location(location); printf("\n=======\nLOCANDO: \n\n"); // Definir cliente do { printf("> A qual cliente quer locar? "); client = form_client_select(input); } while (client->id == NON_EXIST); puts_client(client); // Tem certeza? if (!be_sure(input)) { printf("Abortando locacao.\n\n"); erase_location(location); free(location); return; } location->id_client = client->id; free(client); // Definir filmes if (form_items_insert(location, input) < 1) { free(location); erase_location(location); printf("Voce precisa inserir algum filme a locacao. Abortando locacao.\n\n"); return; } // Imprimir resultado geral printf("\n>>>> SUMARIO DA LOCACAO <<<< \n\n"); puts_location(location, TRUE); printf("-------------------------------------\n\n"); if (update_location(location)) { printf("Locacao foi um sucesso.\n"); } else { printf("Locacao nao foi completada corretamente!\n"); } printf("\n=======\n"); free(location); }
static GtkTreeModel * gweather_timezone_model_new (GWeatherLocation *top) { GtkTreeStore *store; GtkTreeModel *model; GtkTreeIter iter; char *unknown; GWeatherTimezone *utc; store = gtk_tree_store_new (2, G_TYPE_STRING, GWEATHER_TYPE_TIMEZONE); model = GTK_TREE_MODEL (store); unknown = g_markup_printf_escaped ("<i>%s</i>", C_("timezone", "Unknown")); gtk_tree_store_append (store, &iter, NULL); gtk_tree_store_set (store, &iter, GWEATHER_TIMEZONE_MENU_NAME, unknown, GWEATHER_TIMEZONE_MENU_ZONE, NULL, -1); utc = gweather_timezone_get_utc (); if (utc) { insert_location (store, utc, NULL, NULL); gweather_timezone_unref (utc); } gtk_tree_store_append (store, &iter, NULL); g_free (unknown); if (!top) top = gweather_location_get_world (); insert_locations (store, top); return model; }
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; }