8000 [R2] Log Multiplexer by maierlars · Pull Request #14667 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

[R2] Log Multiplexer #14667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up testing code.
  • Loading branch information
maierlars committed Aug 20, 2021
commit 9ef20a70cd824e5df0c8698982db6109eaf7d96b
2 changes: 1 addition & 1 deletion arangod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ set(LIB_ARANGO_REPLICATION2_SOURCES
Replication2/ReplicatedLog/types.cpp
Replication2/Version.cpp
RestHandler/RestLogHandler.cpp
Replication2/ReplicatedState/AbstractStateMachine.tpp Replication2/ReplicatedState/AbstractStateMachine.h Replication2/LogMultiplexer.tpp Replication2/LogMultiplexer.h Replication2/Streams/StreamSpecification.h Replication2/Streams/Streams.h Replication2/Streams/MultiplexedValues.h Replication2/Streams/StreamInformationBlock.h)
Replication2/ReplicatedState/AbstractStateMachine.tpp Replication2/ReplicatedState/AbstractStateMachine.h Replication2/Streams/LogMultiplexer.tpp Replication2/Streams/LogMultiplexer.h Replication2/Streams/StreamSpecification.h Replication2/Streams/Streams.h Replication2/Streams/MultiplexedValues.h Replication2/Streams/StreamInformationBlock.h)

set (LIB_ARANGO_METRICS_SOURCES
RestServer/Metrics.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <Futures/Future.h>

#include <Replication2/ReplicatedLog/ILogParticipant.h>
#include <Replication2/ReplicatedLog/LogCommon.h>
#include <Replication2/ReplicatedLog/types.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ struct LogMultiplexerImplementation
std::shared_ptr<Interface> const _interface;
};

} // namespace arangodb::replication2::streams

template <typename Spec>
auto LogDemultiplexer<Spec>::construct(std::shared_ptr<replicated_log::ILogParticipant> interface)
-> std::shared_ptr<LogDemultiplexer> {
Expand All @@ -342,3 +340,5 @@ auto LogMultiplexer<Spec>::construct(std::shared_ptr<arangodb::replication2::rep
return std::make_shared<streams::LogMultiplexerImplementation<Spec, replicated_log::LogLeader>>(
std::move(leader));
}

} // namespace arangodb::replication2::streams
4 changes: 4 additions & 0 deletions arangod/Replication2/Streams/StreamSpecification.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#pragma once
#include <type_traits>
#include <cstdint>

#include <velocypack/Slice.h>
#include <velocypack/Builder.h>

namespace arangodb::replication2::streams {

Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ set(ARANGODB_REPLICATION2_TEST_SOURCES
Replication2/Mocks/PersistedLog.h
Replication2/ReplicatedLog/InMemoryLogTest.cpp
Replication2/Streams/LogDemultiplexerTest.cpp
Replication2/Mocks/FakeReplicatedLog.cpp Replication2/Mocks/FakeReplicatedLog.h)
Replication2/Mocks/FakeReplicatedLog.cpp Replication2/Mocks/FakeReplicatedLog.h Replication2/Streams/TestLogSpecification.cpp Replication2/Streams/TestLogSpecification.h)


if (LINUX)
Expand Down
71 changes: 25 additions & 46 deletions tests/Replication2/Streams/LogDemultiplexerTest.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Lars Maier
////////////////////////////////////////////////////////////////////////////////

#include <gtest/gtest.h>

#include <velocypack/Builder.h>
#include <velocypack/Slice.h>
#include <Replication2/ReplicatedLog/ReplicatedLog.h>
#include <Replication2/Streams/LogMultiplexer.h>

#include <Replication2/Mocks/FakeReplicatedLog.h>
#include <Replication2/Mocks/PersistedLog.h>
#include <Replication2/Mocks/ReplicatedLogMetricsMock.h>

#include <Replication2/ReplicatedLog/ReplicatedLog.h>

#include <Basics/Exceptions.h>
#include <Replication2/LogMultiplexer.h>
#include <Replication2/Streams/TestLogSpecification.h>

using namespace arangodb;
using namespace arangodb::replication2;
using namespace arangodb::replication2::streams;
using namespace arangodb::replication2::test;

struct LogDemuxTest : ::testing::Test {
static auto createReplicatedLog(LogId id = LogId{0})
Expand All @@ -39,44 +58,6 @@ struct LogDemuxTest : ::testing::Test {
}
};

struct default_deserializer {
template <typename T>
auto operator()(serializer_tag_t<T>, velocypack::Slice s) -> T {
return s.extract<T>();
}
};

struct default_serializer {
template <typename T>
void operator()(serializer_tag_t<T>, T const& t, velocypack::Builder& b) {
b.add(velocypack::Value(t));
}
};

/* clang-format off */

inline constexpr auto my_int_stream_id = StreamId{1};
inline constexpr auto my_int_stream_tag = StreamTag{12};

inline constexpr auto my_string_stream_id = StreamId{8};
inline constexpr auto my_string_stream_tag = StreamTag{55};


using MyTestSpecification = stream_descriptor_set<
stream_descriptor<my_int_stream_id, int, tag_descriptor_set<
tag_descriptor<my_int_stream_tag, default_deserializer, default_serializer>
>>,
stream_descriptor<my_string_stream_id, std::string, tag_descriptor_set<
tag_descriptor<my_string_stream_tag, default_deserializer, default_serializer>
>>
>;

/* clang-format on */

#include <Replication2/LogMultiplexer.tpp>
template struct streams::LogDemultiplexer<MyTestSpecification>;
template struct streams::LogMultiplexer<MyTestSpecification>;

TEST_F(LogDemuxTest, leader_follower_test) {
auto ints = {12, 13, 14, 15, 16};
auto strings = {"foo", "bar", "baz", "fuz"};
Expand Down Expand Up @@ -138,8 +119,6 @@ TEST_F(LogDemuxTest, leader_follower_test) {
}
EXPECT_EQ(iter->next(), std::nullopt);
}

LOG_DEVEL << leader->copyInMemoryLog().dump();
}

TEST_F(LogDemuxTest, leader_wait_for) {
Expand Down
28 changes: 28 additions & 0 deletions tests/Replication2/Streams/TestLogSpecification.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Lars Maier
////////////////////////////////////////////////////////////////////////////////

#include "TestLogSpecification.h"

#include "Replication2/Streams/LogMultiplexer.tpp"

template struct arangodb::replication2::streams::LogMultiplexer<arangodb::replication2::test::MyTestSpecification>;
template struct arangodb::replication2::streams::LogDemultiplexer<arangodb::replication2::test::MyTestSpecification>;
71 changes: 71 additions & 0 deletions tests/Replication2/Streams/TestLogSpecification.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Lars Maier
////////////////////////////////////////////////////////////////////////////////

#pragma once

#include <velocypack/Slice.h>
#include <velocypack/Builder.h>

#include <Replication2/Streams/StreamSpecification.h>
#include <Replication2/Streams/LogMultiplexer.h>

namespace arangodb::replication2::test {

inline constexpr auto my_int_stream_tag = streams::StreamTag{12};
inline constexpr auto my_string_stream_id = streams::StreamId{8};

inline constexpr auto my_string_stream_tag = streams::StreamTag{55};
inline constexpr auto my_int_stream_id = streams::StreamId{1};


struct default_deserializer {
template <typename T>
auto operator()(streams::serializer_tag_t<T>, velocypack::Slice s) -> T {
return s.extract<T>();
}
};

struct default_serializer {
template <typename T>
void operator()(streams::serializer_tag_t<T>, T const& t, velocypack::Builder& b) {
b.add(velocypack::Value(t));
}
};


/* clang-format off */

using MyTestSpecification = streams::stream_descriptor_set<
streams::stream_descriptor<my_int_stream_id, int, streams::tag_descriptor_set<
streams::tag_descriptor<my_int_stream_tag, default_deserializer, default_serializer>
>>,
streams::stream_descriptor<my_string_stream_id, std::string, streams::tag_descriptor_set<
streams::tag_descriptor<my_string_stream_tag, default_deserializer, default_serializer>
>>
>;

/* clang-format on */

} // namespace arangodb::replication2::test

extern template struct arangodb::replication2::streams::LogMultiplexer<arangodb::replication2::test::MyTestSpecification>;
extern template struct arangodb::replication2::streams::LogDemultiplexer<arangodb::replication2::test::MyTestSpecification>;
0