diff --git a/storage/ndb/src/kernel/blocks/dbtup/DbtupAbort.cpp b/storage/ndb/src/kernel/blocks/dbtup/DbtupAbort.cpp index 4e507d1b690..273ccb9e1e6 100644 --- a/storage/ndb/src/kernel/blocks/dbtup/DbtupAbort.cpp +++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupAbort.cpp @@ -170,7 +170,6 @@ void Dbtup::execTUP_ABORTREQ(Signal* signal) /** * Aborting last operation that performed ALLOC */ - ndbout_c("clearing ALLOC"); tuple_ptr->m_header_bits &= ~(Uint32)Tuple_header::ALLOC; tuple_ptr->m_header_bits |= Tuple_header::FREED; } diff --git a/storage/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp b/storage/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp index 782679eac18..fc3419e694a 100644 --- a/storage/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp +++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp @@ -473,13 +473,16 @@ void Dbtup::execTUP_COMMITREQ(Signal* signal) ptrCheckGuard(regTabPtr, no_of_tablerec, tablerec); PagePtr page; - Tuple_header* tuple_ptr= 0; + Tuple_header* tuple_ptr= (Tuple_header*) + get_ptr(&page, ®OperPtr.p->m_tuple_location, regTabPtr.p); + + bool get_page = false; if(regOperPtr.p->op_struct.m_load_diskpage_on_commit) { + Page_cache_client::Request req; ndbassert(regOperPtr.p->is_first_operation() && regOperPtr.p->is_last_operation()); - Page_cache_client::Request req; /** * Check for page */ @@ -490,15 +493,33 @@ void Dbtup::execTUP_COMMITREQ(Signal* signal) memcpy(&req.m_page, tmp->get_disk_ref_ptr(regTabPtr.p), sizeof(Local_key)); + + if (unlikely(regOperPtr.p->op_struct.op_type == ZDELETE && + tmp->m_header_bits & Tuple_header::DISK_ALLOC)) + { + jam(); + /** + * Insert+Delete + */ + regOperPtr.p->op_struct.m_load_diskpage_on_commit = 0; + regOperPtr.p->op_struct.m_wait_log_buffer = 0; + disk_page_abort_prealloc(signal, regFragPtr.p, + &req.m_page, req.m_page.m_page_idx); + + c_lgman->free_log_space(regFragPtr.p->m_logfile_group_id, + regOperPtr.p->m_undo_buffer_space); + ndbout_c("insert+delete"); + goto skip_disk; + } } else { // initial delete ndbassert(regOperPtr.p->op_struct.op_type == ZDELETE); - tuple_ptr= (Tuple_header*) - get_ptr(&page, ®OperPtr.p->m_tuple_location, regTabPtr.p); memcpy(&req.m_page, tuple_ptr->get_disk_ref_ptr(regTabPtr.p), sizeof(Local_key)); + + ndbassert(tuple_ptr->m_header_bits & Tuple_header::DISK_PART); } req.m_callback.m_callbackData= regOperPtr.i; req.m_callback.m_callbackFunction = @@ -522,6 +543,7 @@ void Dbtup::execTUP_COMMITREQ(Signal* signal) ndbrequire("NOT YET IMPLEMENTED" == 0); break; } + get_page = true; disk_page_set_dirty(*(Ptr*)&m_pgman.m_ptr); regOperPtr.p->m_commit_disk_callback_page= res; regOperPtr.p->op_struct.m_load_diskpage_on_commit= 0; @@ -555,6 +577,7 @@ void Dbtup::execTUP_COMMITREQ(Signal* signal) tuple_ptr = (Tuple_header*) get_ptr(&page, ®OperPtr.p->m_tuple_location,regTabPtr.p); } +skip_disk: req_struct.m_tuple_ptr = tuple_ptr; if(get_tuple_state(regOperPtr.p) == TUPLE_PREPARED) @@ -599,6 +622,8 @@ void Dbtup::execTUP_COMMITREQ(Signal* signal) else { removeActiveOpList(regOperPtr.p, tuple_ptr); + if (get_page) + ndbassert(tuple_ptr->m_header_bits & Tuple_header::DISK_PART); dealloc_tuple(signal, gci, page.p, tuple_ptr, regOperPtr.p, regFragPtr.p, regTabPtr.p); } diff --git a/storage/ndb/src/kernel/blocks/dbtup/DbtupDiskAlloc.cpp b/storage/ndb/src/kernel/blocks/dbtup/DbtupDiskAlloc.cpp index d74e4b6811e..ec3231f55f5 100644 --- a/storage/ndb/src/kernel/blocks/dbtup/DbtupDiskAlloc.cpp +++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupDiskAlloc.cpp @@ -1053,6 +1053,7 @@ Dbtup::disk_page_abort_prealloc_callback(Signal* signal, Ptr fragPtr; getFragmentrec(fragPtr, pagePtr.p->m_fragment_id, tabPtr.p); + disk_page_set_dirty(pagePtr); disk_page_abort_prealloc_callback_1(signal, fragPtr.p, pagePtr, sz); } @@ -1074,6 +1075,13 @@ Dbtup::disk_page_abort_prealloc_callback_1(Signal* signal, ddassert(alloc.calc_page_free_bits(free - used) == old_idx); Uint32 new_idx = alloc.calc_page_free_bits(free - used + sz); +#ifdef VM_TRACE + Local_key key; + key.m_page_no = pagePtr.p->m_page_no; + key.m_file_no = pagePtr.p->m_file_no; + ndbout << "disk_page_abort_prealloc_callback_1" << key << endl; +#endif + Ptr extentPtr; c_extent_pool.getPtr(extentPtr, ext); if (old_idx != new_idx) diff --git a/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp b/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp index 7305827b6ac..de497ed2c2d 100644 --- a/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp +++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp @@ -1407,6 +1407,8 @@ int Dbtup::handleInsertReq(Signal* signal, } req_struct->m_use_rowid = false; base->m_header_bits &= ~(Uint32)Tuple_header::FREE; + base->m_header_bits |= Tuple_header::ALLOC & + (regOperPtr.p->is_first_operation() ? ~0 : 1); } else { @@ -1415,6 +1417,8 @@ int Dbtup::handleInsertReq(Signal* signal, { ndbout_c("no mem insert but rowid (same)"); base->m_header_bits &= ~(Uint32)Tuple_header::FREE; + base->m_header_bits |= Tuple_header::ALLOC & + (regOperPtr.p->is_first_operation() ? ~0 : 1); } else { diff --git a/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp b/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp index 25fc62937c4..36037fba9ed 100644 --- a/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp +++ b/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp @@ -46,7 +46,7 @@ #include extern EventLogger g_eventLogger; -static Gci_container g_empty_gci_container; +static Gci_container_pod g_empty_gci_container; static const Uint32 ACTIVE_GCI_DIRECTORY_SIZE = 4; static const Uint32 ACTIVE_GCI_MASK = ACTIVE_GCI_DIRECTORY_SIZE - 1; @@ -1223,12 +1223,22 @@ operator<<(NdbOut& out, const Gci_container& gci) return out; } +static +NdbOut& +operator<<(NdbOut& out, const Gci_container_pod& gci) +{ + Gci_container* ptr = (Gci_container*)&gci; + out << *ptr; + return out; +} + + static Gci_container* -find_bucket_chained(Vector * active, Uint64 gci) +find_bucket_chained(Vector * active, Uint64 gci) { Uint32 pos = (gci & ACTIVE_GCI_MASK); - Gci_container *bucket= active->getBase() + pos; + Gci_container *bucket= ((Gci_container*)active->getBase()) + pos; if(gci > bucket->m_gci) { @@ -1237,8 +1247,9 @@ find_bucket_chained(Vector * active, Uint64 gci) do { active->fill(move_pos, g_empty_gci_container); - bucket = active->getBase() + pos; // Needs to recomputed after fill - move = active->getBase() + move_pos; + // Needs to recomputed after fill + bucket = ((Gci_container*)active->getBase()) + pos; + move = ((Gci_container*)active->getBase()) + move_pos; if(move->m_gcp_complete_rep_count == 0) { memcpy(move, bucket, sizeof(Gci_container)); @@ -1269,10 +1280,10 @@ find_bucket_chained(Vector * active, Uint64 gci) inline Gci_container* -find_bucket(Vector * active, Uint64 gci) +find_bucket(Vector * active, Uint64 gci) { Uint32 pos = (gci & ACTIVE_GCI_MASK); - Gci_container *bucket= active->getBase() + pos; + Gci_container *bucket= ((Gci_container*)active->getBase()) + pos; if(likely(gci == bucket->m_gci)) return bucket; @@ -1370,7 +1381,8 @@ NdbEventBuffer::execSUB_GCP_COMPLETE_REP(const SubGcpCompleteRep * const rep) { /** out of order something */ ndbout_c("out of order bucket: %d gci: %lld m_latestGCI: %lld", - bucket-m_active_gci.getBase(), gci, m_latestGCI); + bucket-(Gci_container*)m_active_gci.getBase(), + gci, m_latestGCI); bucket->m_state = Gci_container::GC_COMPLETE; bucket->m_gcp_complete_rep_count = 1; // Prevent from being reused m_latest_complete_GCI = gci; @@ -1387,7 +1399,7 @@ NdbEventBuffer::complete_outof_order_gcis() Uint64 stop_gci = m_latest_complete_GCI; const Uint32 size = m_active_gci.size(); - Gci_container* array= m_active_gci.getBase(); + Gci_container* array= (Gci_container*)m_active_gci.getBase(); ndbout_c("complete_outof_order_gcis"); for(Uint32 i = 0; i; +template class Vector; template class Vector; diff --git a/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp b/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp index bffc2174be5..8d413cc8d14 100644 --- a/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp +++ b/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp @@ -272,6 +272,11 @@ struct Gci_container EventBufData_hash m_data_hash; }; +struct Gci_container_pod +{ + char data[sizeof(Gci_container)]; +}; + class NdbEventOperationImpl : public NdbEventOperation { public: NdbEventOperationImpl(NdbEventOperation &f, @@ -365,7 +370,7 @@ public: ~NdbEventBuffer(); const Uint32 &m_system_nodes; - Vector m_active_gci; + Vector m_active_gci; NdbEventOperation *createEventOperation(const char* eventName, NdbError &); NdbEventOperationImpl *createEventOperation(NdbEventImpl& evnt, diff --git a/storage/ndb/test/ndbapi/testBasic.cpp b/storage/ndb/test/ndbapi/testBasic.cpp index 879a4979220..69f3d8daef6 100644 --- a/storage/ndb/test/ndbapi/testBasic.cpp +++ b/storage/ndb/test/ndbapi/testBasic.cpp @@ -1034,6 +1034,38 @@ runMassiveRollback2(NDBT_Context* ctx, NDBT_Step* step){ return result; } +int +runMassiveRollback3(NDBT_Context* ctx, NDBT_Step* step){ + + int result = NDBT_OK; + HugoOperations hugoOps(*ctx->getTab()); + Ndb* pNdb = GETNDB(step); + + const Uint32 BATCH = 10; + const Uint32 OPS_TOTAL = 20; + const Uint32 LOOPS = 100; + + for(Uint32 loop = 0; loop