You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2016/01/19 00:19:15 UTC
[3/3] qpid-dispatch git commit: DISPATCH-179 - Added a new facility
to efficiently convert trace lists into bitmasks describing a set of routers.
This will be used to properly implement loop-prevention in the core (the resu
DISPATCH-179 - Added a new facility to efficiently convert trace lists into bitmasks
describing a set of routers. This will be used to properly implement
loop-prevention in the core (the resulting bitmasks will be used by the
core as an exclusion list for forwarding).
Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/025cf4fa
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/025cf4fa
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/025cf4fa
Branch: refs/heads/tross-DISPATCH-179-1
Commit: 025cf4fa5d1ec602d1b128ae2b38a42745fcafbd
Parents: 65234d7
Author: Ted Ross <tr...@redhat.com>
Authored: Mon Jan 18 18:16:36 2016 -0500
Committer: Ted Ross <tr...@redhat.com>
Committed: Mon Jan 18 18:16:36 2016 -0500
----------------------------------------------------------------------
include/qpid/dispatch/trace_mask.h | 75 ++++++++++++++++++++
src/CMakeLists.txt | 1 +
src/trace_mask.c | 119 ++++++++++++++++++++++++++++++++
3 files changed, 195 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/025cf4fa/include/qpid/dispatch/trace_mask.h
----------------------------------------------------------------------
diff --git a/include/qpid/dispatch/trace_mask.h b/include/qpid/dispatch/trace_mask.h
new file mode 100644
index 0000000..7b025b0
--- /dev/null
+++ b/include/qpid/dispatch/trace_mask.h
@@ -0,0 +1,75 @@
+#ifndef __trace_mask_h__
+#define __trace_mask_h__ 1
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 <qpid/dispatch/dispatch.h>
+#include <qpid/dispatch/parse.h>
+#include <qpid/dispatch/bitmask.h>
+
+typedef struct qd_tracemask_t qd_tracemask_t;
+
+/**
+ * qd_tracemask
+ *
+ * Create a TraceMask object.
+ */
+qd_tracemask_t *qd_tracemask(void);
+
+/**
+ * qd_tracemask_free
+ *
+ * Destroy a TraceMask object and free its allocated resources.
+ */
+void qd_tracemask_free(qd_tracemask_t *tm);
+
+/**
+ * qd_tracemask_add_router
+ *
+ * Notify the TraceMask of a new router and its assigned mask bit.
+ *
+ * @param tm Tracemask created by qd_tracemask()
+ * @param address The address of the remote router as reported by the router module.
+ * @param maskbit The mask bit assigned to this router by the router module.
+ */
+void qd_tracemask_add_router(qd_tracemask_t *tm, const char *address, int maskbit);
+
+/**
+ * qd_tracemask_del_router
+ *
+ * Notify the TraceMask of the removal of a router.
+ *
+ * @param tm Tracemask created by qd_tracemask()
+ * @param maskbit The mask bit assigned to this router by the router module.
+ */
+void qd_tracemask_del_router(qd_tracemask_t *tm, int maskbit);
+
+/**
+ * qd_tracemask_create
+ *
+ * Create a new bitmask with a bit set for every router mentioned in the trace list.
+ *
+ * @param tm Tracemask created by qd_tracemask()
+ * @param tracelist The parsed field from a message's trace header
+ * @return A new bit mask with a set-bit for each router in the list. This must be freed
+ * by the caller when the caller is done with it.
+ */
+qd_bitmask_t *qd_tracemask_create(qd_tracemask_t *tm, qd_parsed_field_t *tracelist);
+
+#endif
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/025cf4fa/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5301081..5ae8076 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -82,6 +82,7 @@ set(qpid_dispatch_SOURCES
schema_enum.c
server.c
timer.c
+ trace_mask.c
)
if(USE_MEMORY_POOL)
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/025cf4fa/src/trace_mask.c
----------------------------------------------------------------------
diff --git a/src/trace_mask.c b/src/trace_mask.c
new file mode 100644
index 0000000..b5c505a
--- /dev/null
+++ b/src/trace_mask.c
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 <qpid/dispatch/trace_mask.h>
+#include <qpid/dispatch/iterator.h>
+#include <qpid/dispatch/threading.h>
+#include <qpid/dispatch/hash.h>
+#include "alloc.h"
+
+typedef struct {
+ qd_hash_handle_t *hash_handle;
+ int maskbit;
+} qdtm_router_t;
+
+ALLOC_DECLARE(qdtm_router_t);
+ALLOC_DEFINE(qdtm_router_t);
+
+struct qd_tracemask_t {
+ sys_rwlock_t *lock;
+ qd_hash_t *hash;
+ qdtm_router_t **router_by_mask_bit;
+};
+
+
+qd_tracemask_t *qd_tracemask(void)
+{
+ qd_tracemask_t *tm = NEW(qd_tracemask_t);
+ tm->lock = sys_rwlock();
+ tm->hash = qd_hash(8, 1, 0);
+ tm->router_by_mask_bit = NEW_PTR_ARRAY(qdtm_router_t, qd_bitmask_width());
+
+ for (int i = 0; i < qd_bitmask_width(); i++)
+ tm->router_by_mask_bit[i] = 0;
+ return tm;
+}
+
+
+void qd_tracemask_free(qd_tracemask_t *tm)
+{
+ for (int i = 0; i < qd_bitmask_width(); i++) {
+ if (tm->router_by_mask_bit[i])
+ qd_tracemask_del_router(tm, i);
+ }
+
+ qd_hash_free(tm->hash);
+ sys_rwlock_free(tm->lock);
+ free(tm);
+}
+
+
+void qd_tracemask_add_router(qd_tracemask_t *tm, const char *address, int maskbit)
+{
+ qd_field_iterator_t *iter = qd_address_iterator_string(address, ITER_VIEW_NODE_HASH);
+ sys_rwlock_wrlock(tm->lock);
+ assert(maskbit < qd_bitmask_width() && tm->router_by_mask_bit[maskbit] == 0);
+ if (maskbit < qd_bitmask_width() && tm->router_by_mask_bit[maskbit] == 0) {
+ qdtm_router_t *router = new_qdtm_router_t();
+ router->maskbit = maskbit;
+ qd_hash_insert(tm->hash, iter, router, &router->hash_handle);
+ tm->router_by_mask_bit[maskbit] = router;
+ }
+ sys_rwlock_unlock(tm->lock);
+ qd_field_iterator_free(iter);
+}
+
+
+void qd_tracemask_del_router(qd_tracemask_t *tm, int maskbit)
+{
+ sys_rwlock_wrlock(tm->lock);
+ assert(maskbit < qd_bitmask_width() && tm->router_by_mask_bit[maskbit] != 0);
+ if (maskbit < qd_bitmask_width() && tm->router_by_mask_bit[maskbit] != 0) {
+ qdtm_router_t *router = tm->router_by_mask_bit[maskbit];
+ qd_hash_remove_by_handle(tm->hash, router->hash_handle);
+ tm->router_by_mask_bit[maskbit] = 0;
+ free_qdtm_router_t(router);
+ }
+ sys_rwlock_unlock(tm->lock);
+}
+
+
+qd_bitmask_t *qd_tracemask_create(qd_tracemask_t *tm, qd_parsed_field_t *tracelist)
+{
+ qd_bitmask_t *bm = qd_bitmask(0);
+ int idx = 0;
+
+ assert(qd_parse_is_list(tracelist));
+
+ sys_rwlock_rdlock(tm->lock);
+ qd_parsed_field_t *item = qd_parse_sub_value(tracelist, idx);
+ qdtm_router_t *router = 0;
+ while (item) {
+ qd_field_iterator_t *iter = qd_parse_raw(item);
+ qd_address_iterator_reset_view(iter, ITER_VIEW_NODE_HASH);
+ qd_hash_retrieve(tm->hash, iter, (void*) &router);
+ if (router)
+ qd_bitmask_set_bit(bm, router->maskbit);
+ idx++;
+ item = qd_parse_sub_value(tracelist, idx);
+ }
+ sys_rwlock_unlock(tm->lock);
+ return bm;
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org