Merge remote-tracking branch 'origin/topic/awelzel/3342-fix-broker-composite-key-tables-deletion'

* origin/topic/awelzel/3342-fix-broker-composite-key-tables-deletion:
  broker/Manager: Fix deletion of composite keys
  Add btest for brokerstore delete with complex index.
This commit is contained in:
Tim Wojtulewicz 2023-10-02 11:42:58 -07:00
commit 9dcf1b4cd1
6 changed files with 98 additions and 3 deletions

View file

@ -1,3 +1,11 @@
6.1.0-dev.482 | 2023-10-02 11:42:58 -0700
* broker/Manager: Fix deletion of composite keys (Arne Welzel, Corelight)
Follow-up for commit 44ae8f9e8f25ff403707026657e000693550873f.
* Add btest for brokerstore delete with complex index. (Jan Grashoefer, Corelight)
6.1.0-dev.479 | 2023-10-02 11:09:13 -0700 6.1.0-dev.479 | 2023-10-02 11:09:13 -0700
* minor updates to -O gen-C++ maintenance notes and scripts (Vern Paxson, Corelight) * minor updates to -O gen-C++ maintenance notes and scripts (Vern Paxson, Corelight)

View file

@ -1 +1 @@
6.1.0-dev.479 6.1.0-dev.482

View file

@ -1338,9 +1338,15 @@ void Manager::ProcessStoreEvent(broker::data msg)
auto key = erase.key(); auto key = erase.key();
DBG_LOG(DBG_BROKER, "Store %s: Erase key %s", erase.store_id().c_str(), DBG_LOG(DBG_BROKER, "Store %s: Erase key %s", erase.store_id().c_str(),
to_string(key).c_str()); to_string(key).c_str());
const auto& its = table->GetType()->AsTableType()->GetIndexTypes(); const auto& its = table->GetType()->AsTableType()->GetIndexTypes();
assert(its.size() == 1); ValPtr zeek_key;
auto zeek_key = detail::data_to_val(key, its[0].get()); if ( its.size() == 1 )
zeek_key = detail::data_to_val(key, its[0].get());
else
zeek_key = detail::data_to_val(key,
table->GetType()->AsTableType()->GetIndices().get());
if ( ! zeek_key ) if ( ! zeek_key )
{ {
reporter->Error("ProcessStoreEvent: could not convert key \"%s\" for store \"%s\" " reporter->Error("ProcessStoreEvent: could not convert key \"%s\" for store \"%s\" "

View file

@ -0,0 +1,9 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
manager-1, change_handler, TABLE_ELEMENT_NEW, a, 1, 12
manager-1, change_handler, TABLE_ELEMENT_NEW, b, 2, 23
manager-1, change_handler, TABLE_ELEMENT_NEW, c, 3, 42
manager-1, change_handler, TABLE_ELEMENT_REMOVED, b, 2, 23
manager-1, zeek_done, {
[c, 3] = 42,
[a, 1] = 12
}

View file

@ -0,0 +1,11 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
Got cluster_started event
worker-1, change_handler, TABLE_ELEMENT_NEW, a, 1, 12
worker-1, change_handler, TABLE_ELEMENT_NEW, b, 2, 23
worker-1, change_handler, TABLE_ELEMENT_NEW, c, 3, 42
worker-1, change_handler, TABLE_ELEMENT_REMOVED, b, 2, 23
worker-1, peer_lost
worker-1, zeek_done, {
[c, 3] = 42,
[a, 1] = 12
}

View file

@ -0,0 +1,61 @@
# @TEST-DOC: Test deletion of elements in a broker backed table with composite keys. Regression test for #3342.
#
# @TEST-PORT: BROKER_PORT1
# @TEST-PORT: BROKER_PORT2
#
# @TEST-EXEC: btest-bg-run manager-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=manager-1 zeek -b %INPUT
# @TEST-EXEC: btest-bg-run worker-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-1 zeek -b %INPUT
# @TEST-EXEC: btest-bg-wait 20
# @TEST-EXEC: btest-diff manager-1/.stdout
# @TEST-EXEC: btest-diff worker-1/.stdout
@load policy/frameworks/cluster/experimental
@TEST-START-FILE cluster-layout.zeek
redef Cluster::nodes = {
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))],
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"],
};
@TEST-END-FILE
function change_handler(t: table[string, count] of count, tpe: TableChange,
k0: string, k1: count, v: count)
{
print Cluster::node, "change_handler", tpe, k0, k1, v;
# Terminate the manager when it sees the removed table element.
if ( tpe == TABLE_ELEMENT_REMOVED && Cluster::local_node_type() == Cluster::MANAGER )
terminate();
}
global t: table[string, count] of count &backend=Broker::MEMORY &on_change=change_handler;
event zeek_done()
{
print Cluster::node, "zeek_done", t;
}
# The worker populates the broker backed table and deletes a single entry,
# then waits on the manager before terminating itself.
@if ( Cluster::local_node_type() == Cluster::WORKER )
event do_delete()
{
delete t["b", 2];
}
event Cluster::Experimental::cluster_started()
{
print "Got cluster_started event";
t["a", 1] = 12;
t["b", 2] = 23;
t["c", 3] = 42;
schedule 0.01sec { do_delete() };
}
event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
{
print Cluster::node, "peer_lost";
terminate();
}
@endif