diff options
author | Ben Pfaff <blp@ovn.org> | 2016-04-18 22:50:25 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2016-04-18 22:50:25 -0700 |
commit | bd3b4403b10847cff1e113920ed9c0612c892062 (patch) | |
tree | 0aa46a7af745dc2c98898cb4f374b8f2a9725648 | |
parent | 8b72f5f7f2aa8aa6060cb9ad29e714066d204826 (diff) | |
download | openvswitch-bd3b4403b10847cff1e113920ed9c0612c892062.tar.gz |
start playing with the code
-rw-r--r-- | lib/automake.mk | 2 | ||||
-rw-r--r-- | ovsdb/automake.mk | 2 | ||||
-rw-r--r-- | ovsdb/ovsdb-tool.c | 6 | ||||
-rw-r--r-- | ovsdb/raft.c (renamed from lib/raft.c) | 31 | ||||
-rw-r--r-- | ovsdb/raft.h (renamed from lib/raft.h) | 0 | ||||
-rw-r--r-- | tests/automake.mk | 4 | ||||
-rw-r--r-- | tests/test-raft.c | 52 |
7 files changed, 90 insertions, 7 deletions
diff --git a/lib/automake.mk b/lib/automake.mk index 4eee0c684..7b829d0db 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -199,8 +199,6 @@ lib_libopenvswitch_la_SOURCES = \ lib/process.h \ lib/pvector.c \ lib/pvector.h \ - lib/raft.c \ - lib/raft.h \ lib/random.c \ lib/random.h \ lib/rconn.c \ diff --git a/ovsdb/automake.mk b/ovsdb/automake.mk index 7db6fea66..030b66f83 100644 --- a/ovsdb/automake.mk +++ b/ovsdb/automake.mk @@ -24,6 +24,8 @@ ovsdb_libovsdb_la_SOURCES = \ ovsdb/monitor.h \ ovsdb/query.c \ ovsdb/query.h \ + ovsdb/raft.c \ + ovsdb/raft.h \ ovsdb/row.c \ ovsdb/row.h \ ovsdb/server.c \ diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c index 213046a11..060d52525 100644 --- a/ovsdb/ovsdb-tool.c +++ b/ovsdb/ovsdb-tool.c @@ -218,8 +218,8 @@ static void do_create_cluster(struct ovs_cmdl_context *ctx) { const char *db_file_name = ctx->argv[1]; - const char *address = ctx->argv[2]; - const char *schema_file_name = ctx->argv[3]; + const char *schema_file_name = ctx->argv[2]; + const char *address = ctx->argv[3]; /* Read schema from file and convert to JSON. */ struct ovsdb_schema *schema; @@ -603,7 +603,7 @@ do_list_commands(struct ovs_cmdl_context *ctx OVS_UNUSED) static const struct ovs_cmdl_command all_commands[] = { { "create", "[db [schema]]", 0, 2, do_create }, - { "create-cluster", "db address db schema", 3, 3, do_create_cluster }, + { "create-cluster", "db schema address", 3, 3, do_create_cluster }, { "compact", "[db [dst]]", 0, 2, do_compact }, { "convert", "[db [schema [dst]]]", 0, 3, do_convert }, { "needs-conversion", NULL, 0, 2, do_needs_conversion }, diff --git a/lib/raft.c b/ovsdb/raft.c index 2a179835a..bf4d4d0ec 100644 --- a/lib/raft.c +++ b/ovsdb/raft.c @@ -30,6 +30,7 @@ #include "ovsdb-error.h" #include "ovsdb-parser.h" #include "ovsdb/log.h" +#include "poll-loop.h" #include "socket-util.h" #include "stream.h" #include "timeval.h" @@ -469,7 +470,7 @@ static char * raft_make_address_passive(const char *address_) { char *address = xstrdup(address_); - char *p = address; + char *p = strchr(address, ':') + 1; char *host = inet_parse_token(&p); char *port = inet_parse_token(&p); @@ -1058,7 +1059,9 @@ raft_run(struct raft *raft) if (!s->js && s != raft->me) { s->js = jsonrpc_session_open(s->address, true); } - raft_run_session(raft, s->js, &s->sid); + if (s->js) { + raft_run_session(raft, s->js, &s->sid); + } } struct raft_conn *conn, *next; @@ -1071,6 +1074,30 @@ raft_run(struct raft *raft) } } } + +void +raft_wait(struct raft *raft) +{ + if (raft->listener) { + pstream_wait(raft->listener); + } else { + poll_timer_wait_until(raft->listen_backoff); + } + + struct raft_server *s; + HMAP_FOR_EACH (s, hmap_node, &raft->servers) { + if (s->js) { + jsonrpc_session_wait(s->js); + jsonrpc_session_recv_wait(s->js); + } + } + + struct raft_conn *conn; + LIST_FOR_EACH (conn, list_node, &raft->conns) { + jsonrpc_session_wait(conn->js); + jsonrpc_session_recv_wait(conn->js); + } +} static void raft_rpc_destroy(union raft_rpc *rpc) diff --git a/lib/raft.h b/ovsdb/raft.h index bd6d8c695..bd6d8c695 100644 --- a/lib/raft.h +++ b/ovsdb/raft.h diff --git a/tests/automake.mk b/tests/automake.mk index 3abe3700c..ae2ddaea2 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -252,6 +252,10 @@ nodist_tests_test_ovsdb_SOURCES = tests/idltest.c tests/idltest.h EXTRA_DIST += tests/uuidfilt.pl tests/ovsdb-monitor-sort.pl tests_test_ovsdb_LDADD = ovsdb/libovsdb.la lib/libopenvswitch.la +noinst_PROGRAMS += tests/test-raft +tests_test_raft_SOURCES = tests/test-raft.c +tests_test_raft_LDADD = ovsdb/libovsdb.la lib/libopenvswitch.la + noinst_PROGRAMS += tests/test-lib tests_test_lib_SOURCES = \ tests/test-lib.c diff --git a/tests/test-raft.c b/tests/test-raft.c new file mode 100644 index 000000000..05f1b13e8 --- /dev/null +++ b/tests/test-raft.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2009, 2010, 2014 Nicira, Inc. + * + * 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. + */ + +#include <config.h> +#include <getopt.h> +#include "ovsdb/raft.h" +#include <stdio.h> +#include "ovsdb-error.h" +#include "poll-loop.h" +#include "util.h" + +static void +check_ovsdb_error(struct ovsdb_error *error) +{ + if (error) { + char *s = ovsdb_error_to_string(error); + ovsdb_error_destroy(error); + ovs_fatal(0, "%s", s); + } +} + +int +main(int argc, char *argv[]) +{ + set_program_name(argv[0]); + + if (argc - optind != 1) { + ovs_fatal(0, "usage: %s LOG", program_name); + } + + struct raft *raft; + check_ovsdb_error(raft_open(argv[optind], &raft)); + + for (;;) { + raft_run(raft); + raft_wait(raft); + poll_block(); + } +} |