@@ -2019,6 +2019,67 @@ TEST_P(CoordinationTest, TestCreateNodeWithAuthSchemeForAclWhenAuthIsPrecommitte
20192019 EXPECT_EQ (acls[0 ].permissions , 31 );
20202020}
20212021
2022+ TEST_P (CoordinationTest, TestPreprocessWhenCloseSessionIsPrecommitted)
2023+ {
2024+ using namespace Coordination ;
2025+ using namespace DB ;
2026+
2027+ ChangelogDirTest snapshots (" ./snapshots" );
2028+ setSnapshotDirectory (" ./snapshots" );
2029+ ResponsesQueue queue (std::numeric_limits<size_t >::max ());
2030+ SnapshotsQueue snapshots_queue{1 };
2031+ int64_t session_id = 1 ;
2032+ size_t term = 0 ;
2033+
2034+ auto state_machine = std::make_shared<KeeperStateMachine>(queue, snapshots_queue, keeper_context, nullptr );
2035+ state_machine->init ();
2036+
2037+ auto & storage = state_machine->getStorageUnsafe ();
2038+ const auto & uncommitted_state = storage.uncommitted_state ;
2039+
2040+ // Create first node for the session
2041+ String node_path_1 = " /node_1" ;
2042+ std::shared_ptr<ZooKeeperCreateRequest> create_req_1 = std::make_shared<ZooKeeperCreateRequest>();
2043+ create_req_1->path = node_path_1;
2044+ auto create_entry_1 = getLogEntryFromZKRequest (term, session_id, state_machine->getNextZxid (), create_req_1);
2045+
2046+ state_machine->pre_commit (1 , create_entry_1->get_buf ());
2047+ EXPECT_TRUE (uncommitted_state.nodes .contains (node_path_1));
2048+
2049+ state_machine->commit (1 , create_entry_1->get_buf ());
2050+ EXPECT_TRUE (storage.container .contains (node_path_1));
2051+
2052+ // Close session
2053+ std::shared_ptr<ZooKeeperCloseRequest> close_req = std::make_shared<ZooKeeperCloseRequest>();
2054+ auto close_entry = getLogEntryFromZKRequest (term, session_id, state_machine->getNextZxid (), close_req);
2055+ // Pre-commit close session
2056+ state_machine->pre_commit (2 , close_entry->get_buf ());
2057+
2058+ // Try to create second node after close session is pre-committed
2059+ String node_path_2 = " /node_2" ;
2060+ std::shared_ptr<ZooKeeperCreateRequest> create_req_2 = std::make_shared<ZooKeeperCreateRequest>();
2061+ create_req_2->path = node_path_2;
2062+ auto create_entry_2 = getLogEntryFromZKRequest (term, session_id, state_machine->getNextZxid (), create_req_2);
2063+
2064+ // Pre-commit creating second node
2065+ state_machine->pre_commit (3 , create_entry_2->get_buf ());
2066+ // Second node wasn't created
2067+ EXPECT_FALSE (uncommitted_state.nodes .contains (node_path_2));
2068+
2069+ // Rollback pre-committed closing session
2070+ state_machine->rollback (3 , create_entry_2->get_buf ());
2071+ state_machine->rollback (2 , close_entry->get_buf ());
2072+
2073+ // Pre-commit creating second node
2074+ state_machine->pre_commit (2 , create_entry_2->get_buf ());
2075+ // Now second node was created
2076+ EXPECT_TRUE (uncommitted_state.nodes .contains (node_path_2));
2077+
2078+ state_machine->commit (2 , create_entry_2->get_buf ());
2079+ EXPECT_TRUE (storage.container .contains (node_path_1));
2080+ EXPECT_TRUE (storage.container .contains (node_path_2));
2081+ }
2082+
20222083TEST_P (CoordinationTest, TestSetACLWithAuthSchemeForAclWhenAuthIsPrecommitted)
20232084{
20242085 using namespace Coordination ;
0 commit comments