You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2012/11/17 07:23:21 UTC
[1/4] git commit: TS-1551: Move ProxyConfig down to libmgmt
Updated Branches:
refs/heads/master 54b82f288 -> 21b5552a4
TS-1551: Move ProxyConfig down to libmgmt
ProxyConfig doesn't have any proxy dependencies and it's a more
generic model for handling reconfiguration that the custom code
that is used everywhere. Pushing it down into libmgmt lets us use
it in iocore without a dirty layering violation.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/82144fbe
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/82144fbe
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/82144fbe
Branch: refs/heads/master
Commit: 82144fbe108da4113ae0b460acb25a8c9a59b123
Parents: b4816b0
Author: James Peach <jp...@apache.org>
Authored: Fri Nov 16 21:24:31 2012 -0800
Committer: James Peach <jp...@apache.org>
Committed: Fri Nov 16 22:22:51 2012 -0800
----------------------------------------------------------------------
mgmt/Makefile.am | 2 +
mgmt/ProxyConfig.cc | 204 +++++++++++++++++++++++++++++++++++++++++++++
mgmt/ProxyConfig.h | 83 ++++++++++++++++++
proxy/Makefile.am | 4 -
proxy/ProxyConfig.cc | 204 ---------------------------------------------
proxy/ProxyConfig.h | 83 ------------------
6 files changed, 289 insertions(+), 291 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/82144fbe/mgmt/Makefile.am
----------------------------------------------------------------------
diff --git a/mgmt/Makefile.am b/mgmt/Makefile.am
index 2dd5451..cab49df 100644
--- a/mgmt/Makefile.am
+++ b/mgmt/Makefile.am
@@ -64,6 +64,8 @@ libmgmt_p_a_SOURCES = \
MgmtDefs.h \
ProcessManager.cc \
ProcessManager.h \
+ ProxyConfig.cc \
+ ProxyConfig.h \
RecordsConfig.cc \
RecordsConfig.h
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/82144fbe/mgmt/ProxyConfig.cc
----------------------------------------------------------------------
diff --git a/mgmt/ProxyConfig.cc b/mgmt/ProxyConfig.cc
new file mode 100644
index 0000000..593b0ae
--- /dev/null
+++ b/mgmt/ProxyConfig.cc
@@ -0,0 +1,204 @@
+/** @file
+
+ A brief file description
+
+ @section license License
+
+ 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 "libts.h"
+#include "ProxyConfig.h"
+#include "P_EventSystem.h"
+
+ConfigProcessor configProcessor;
+
+
+void *
+config_int_cb(void *data, void *value)
+{
+ *(int *) data = *(int64_t *) value;
+ return NULL;
+}
+
+void *
+config_float_cb(void *data, void *value)
+{
+ *(float *) data = *(float *) value;
+ return NULL;
+}
+
+void *
+config_long_long_cb(void *data, void *value)
+{
+ *(int64_t *) data = *(int64_t *) value;
+ return NULL;
+}
+
+/////////////////////////////////////////////////////////////
+//
+// config_string_alloc_cb()
+//
+// configuration callback function. The function is called
+// by the manager when a string configuration variable
+// changed. It allocates new memory for the new data.
+// the old variable is scheduled to be freed using
+// ConfigFreerContinuation which will free the memory
+// used for this variable after long time, assuming that
+// during all this time all the users of this memory will
+// disappear.
+/////////////////////////////////////////////////////////////
+void *
+config_string_alloc_cb(void *data, void *value)
+{
+ char *_ss = (char *) value;
+ char *_new_value = 0;
+
+//#define DEBUG_CONFIG_STRING_UPDATE
+#if defined (DEBUG_CONFIG_STRING_UPDATE)
+ printf("config callback [new, old] = [%s : %s]\n",
+ (_ss) ? (_ss) : (""), (*(char **) data) ? (*(char **) data) : (""));
+#endif
+ int len = -1;
+ if (_ss) {
+ len = strlen(_ss);
+ _new_value = (char *)ats_malloc(len + 1);
+ memcpy(_new_value, _ss, len + 1);
+ }
+
+ char *_temp2 = *(char **) data;
+ *(char **) data = _new_value;
+
+ // free old data
+ if (_temp2 != 0)
+ new_Freer(_temp2, HRTIME_DAY);
+
+ return NULL;
+}
+
+
+class ConfigInfoReleaser:public Continuation
+{
+public:
+ ConfigInfoReleaser(unsigned int id, ConfigInfo * info)
+ : Continuation(new_ProxyMutex()), m_id(id), m_info(info)
+ {
+ SET_HANDLER(&ConfigInfoReleaser::handle_event);
+ }
+
+ int handle_event(int event, void *edata)
+ {
+ NOWARN_UNUSED(event);
+ NOWARN_UNUSED(edata);
+ configProcessor.release(m_id, m_info);
+ delete this;
+ return 0;
+ }
+
+public:
+ unsigned int m_id;
+ ConfigInfo *m_info;
+};
+
+
+ConfigProcessor::ConfigProcessor()
+ : ninfos(0)
+{
+ int i;
+
+ for (i = 0; i < MAX_CONFIGS; i++) {
+ infos[i] = NULL;
+ }
+}
+
+unsigned int
+ConfigProcessor::set(unsigned int id, ConfigInfo * info)
+{
+ ConfigInfo *old_info;
+ int idx;
+
+ if (id == 0) {
+ id = ink_atomic_increment((int *) &ninfos, 1) + 1;
+ ink_assert(id != 0);
+ ink_assert(id <= MAX_CONFIGS);
+ }
+
+ info->m_refcount = 1;
+
+ if (id > MAX_CONFIGS) {
+ // invalid index
+ Error("[ConfigProcessor::set] invalid index");
+ return 0;
+ }
+
+ idx = id - 1;
+
+ do {
+ old_info = (ConfigInfo *) infos[idx];
+ } while (!ink_atomic_cas( & infos[idx], old_info, info));
+
+ if (old_info) {
+ eventProcessor.schedule_in(NEW(new ConfigInfoReleaser(id, old_info)), HRTIME_SECONDS(60));
+ }
+
+ return id;
+}
+
+ConfigInfo *
+ConfigProcessor::get(unsigned int id)
+{
+ ConfigInfo *info;
+ int idx;
+
+ ink_assert(id != 0);
+ ink_assert(id <= MAX_CONFIGS);
+
+ if (id == 0 || id > MAX_CONFIGS) {
+ // return NULL, because we of an invalid index
+ return NULL;
+ }
+
+ idx = id - 1;
+ info = (ConfigInfo *) infos[idx];
+ if (ink_atomic_increment((int *) &info->m_refcount, 1) < 0) {
+ ink_assert(!"not reached");
+ }
+
+ return info;
+}
+
+void
+ConfigProcessor::release(unsigned int id, ConfigInfo * info)
+{
+ int val;
+ int idx;
+
+ ink_assert(id != 0);
+ ink_assert(id <= MAX_CONFIGS);
+
+ if (id == 0 || id > MAX_CONFIGS) {
+ // nothing to delete since we have an invalid index
+ return;
+ }
+
+ idx = id - 1;
+ val = ink_atomic_increment((int *) &info->m_refcount, -1);
+
+ if ((infos[idx] != info) && (val == 1)) {
+ delete info;
+ }
+}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/82144fbe/mgmt/ProxyConfig.h
----------------------------------------------------------------------
diff --git a/mgmt/ProxyConfig.h b/mgmt/ProxyConfig.h
new file mode 100644
index 0000000..6a3811d
--- /dev/null
+++ b/mgmt/ProxyConfig.h
@@ -0,0 +1,83 @@
+/** @file
+
+ A brief file description
+
+ @section license License
+
+ 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.
+ */
+
+/****************************************************************************
+
+ ProxyConfig.h
+
+
+ ****************************************************************************/
+
+#ifndef _Proxy_Config_h
+#define _Proxy_Config_h
+
+#include "libts.h"
+#include "ProcessManager.h"
+
+void *config_int_cb(void *data, void *value);
+void *config_long_long_cb(void *data, void *value);
+void *config_float_cb(void *data, void *value);
+void *config_string511_cb(void *data, void *value);
+void *config_string_alloc_cb(void *data, void *value);
+
+//
+// Macros that spin waiting for the data to be bound
+//
+#define SignalManager(_n,_d) pmgmt->signalManager(_n,(char*)_d)
+#define SignalWarning(_n,_s) { Warning("%s", _s); SignalManager(_n,_s); }
+
+#define RegisterMgmtCallback(_signal,_fn,_data) \
+pmgmt->registerMgmtCallback(_signal,_fn,_data)
+
+
+#define MAX_CONFIGS 100
+
+
+struct ConfigInfo
+{
+ volatile int m_refcount;
+
+ virtual ~ ConfigInfo()
+ {
+ }
+};
+
+
+class ConfigProcessor
+{
+public:
+ ConfigProcessor();
+
+ unsigned int set(unsigned int id, ConfigInfo * info);
+ ConfigInfo *get(unsigned int id);
+ void release(unsigned int id, ConfigInfo * data);
+
+public:
+ ConfigInfo *infos[MAX_CONFIGS];
+ int ninfos;
+};
+
+
+extern ConfigProcessor configProcessor;
+
+#endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/82144fbe/proxy/Makefile.am
----------------------------------------------------------------------
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 232c60f..5cce029 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -71,8 +71,6 @@ traffic_server_SOURCES = \
AbstractBuffer.h \
CacheControl.cc \
CacheControl.h \
- ProxyConfig.cc \
- ProxyConfig.h \
ControlBase.cc \
ControlBase.h \
ControlMatcher.cc \
@@ -222,7 +220,6 @@ traffic_sac_LDADD = \
CacheControl.o \
StatSystem.o \
ReverseProxy.o \
- ProxyConfig.o \
signals.o \
Error.o \
EventName.o \
@@ -271,7 +268,6 @@ endif
libTrafficServerStandalone_a_SOURCES = \
signals.cc \
Error.cc \
- ProxyConfig.cc \
EventName.cc \
DiagsConfig.cc \
StatPages.cc \
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/82144fbe/proxy/ProxyConfig.cc
----------------------------------------------------------------------
diff --git a/proxy/ProxyConfig.cc b/proxy/ProxyConfig.cc
deleted file mode 100644
index 593b0ae..0000000
--- a/proxy/ProxyConfig.cc
+++ /dev/null
@@ -1,204 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- 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 "libts.h"
-#include "ProxyConfig.h"
-#include "P_EventSystem.h"
-
-ConfigProcessor configProcessor;
-
-
-void *
-config_int_cb(void *data, void *value)
-{
- *(int *) data = *(int64_t *) value;
- return NULL;
-}
-
-void *
-config_float_cb(void *data, void *value)
-{
- *(float *) data = *(float *) value;
- return NULL;
-}
-
-void *
-config_long_long_cb(void *data, void *value)
-{
- *(int64_t *) data = *(int64_t *) value;
- return NULL;
-}
-
-/////////////////////////////////////////////////////////////
-//
-// config_string_alloc_cb()
-//
-// configuration callback function. The function is called
-// by the manager when a string configuration variable
-// changed. It allocates new memory for the new data.
-// the old variable is scheduled to be freed using
-// ConfigFreerContinuation which will free the memory
-// used for this variable after long time, assuming that
-// during all this time all the users of this memory will
-// disappear.
-/////////////////////////////////////////////////////////////
-void *
-config_string_alloc_cb(void *data, void *value)
-{
- char *_ss = (char *) value;
- char *_new_value = 0;
-
-//#define DEBUG_CONFIG_STRING_UPDATE
-#if defined (DEBUG_CONFIG_STRING_UPDATE)
- printf("config callback [new, old] = [%s : %s]\n",
- (_ss) ? (_ss) : (""), (*(char **) data) ? (*(char **) data) : (""));
-#endif
- int len = -1;
- if (_ss) {
- len = strlen(_ss);
- _new_value = (char *)ats_malloc(len + 1);
- memcpy(_new_value, _ss, len + 1);
- }
-
- char *_temp2 = *(char **) data;
- *(char **) data = _new_value;
-
- // free old data
- if (_temp2 != 0)
- new_Freer(_temp2, HRTIME_DAY);
-
- return NULL;
-}
-
-
-class ConfigInfoReleaser:public Continuation
-{
-public:
- ConfigInfoReleaser(unsigned int id, ConfigInfo * info)
- : Continuation(new_ProxyMutex()), m_id(id), m_info(info)
- {
- SET_HANDLER(&ConfigInfoReleaser::handle_event);
- }
-
- int handle_event(int event, void *edata)
- {
- NOWARN_UNUSED(event);
- NOWARN_UNUSED(edata);
- configProcessor.release(m_id, m_info);
- delete this;
- return 0;
- }
-
-public:
- unsigned int m_id;
- ConfigInfo *m_info;
-};
-
-
-ConfigProcessor::ConfigProcessor()
- : ninfos(0)
-{
- int i;
-
- for (i = 0; i < MAX_CONFIGS; i++) {
- infos[i] = NULL;
- }
-}
-
-unsigned int
-ConfigProcessor::set(unsigned int id, ConfigInfo * info)
-{
- ConfigInfo *old_info;
- int idx;
-
- if (id == 0) {
- id = ink_atomic_increment((int *) &ninfos, 1) + 1;
- ink_assert(id != 0);
- ink_assert(id <= MAX_CONFIGS);
- }
-
- info->m_refcount = 1;
-
- if (id > MAX_CONFIGS) {
- // invalid index
- Error("[ConfigProcessor::set] invalid index");
- return 0;
- }
-
- idx = id - 1;
-
- do {
- old_info = (ConfigInfo *) infos[idx];
- } while (!ink_atomic_cas( & infos[idx], old_info, info));
-
- if (old_info) {
- eventProcessor.schedule_in(NEW(new ConfigInfoReleaser(id, old_info)), HRTIME_SECONDS(60));
- }
-
- return id;
-}
-
-ConfigInfo *
-ConfigProcessor::get(unsigned int id)
-{
- ConfigInfo *info;
- int idx;
-
- ink_assert(id != 0);
- ink_assert(id <= MAX_CONFIGS);
-
- if (id == 0 || id > MAX_CONFIGS) {
- // return NULL, because we of an invalid index
- return NULL;
- }
-
- idx = id - 1;
- info = (ConfigInfo *) infos[idx];
- if (ink_atomic_increment((int *) &info->m_refcount, 1) < 0) {
- ink_assert(!"not reached");
- }
-
- return info;
-}
-
-void
-ConfigProcessor::release(unsigned int id, ConfigInfo * info)
-{
- int val;
- int idx;
-
- ink_assert(id != 0);
- ink_assert(id <= MAX_CONFIGS);
-
- if (id == 0 || id > MAX_CONFIGS) {
- // nothing to delete since we have an invalid index
- return;
- }
-
- idx = id - 1;
- val = ink_atomic_increment((int *) &info->m_refcount, -1);
-
- if ((infos[idx] != info) && (val == 1)) {
- delete info;
- }
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/82144fbe/proxy/ProxyConfig.h
----------------------------------------------------------------------
diff --git a/proxy/ProxyConfig.h b/proxy/ProxyConfig.h
deleted file mode 100644
index 6a3811d..0000000
--- a/proxy/ProxyConfig.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- 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.
- */
-
-/****************************************************************************
-
- ProxyConfig.h
-
-
- ****************************************************************************/
-
-#ifndef _Proxy_Config_h
-#define _Proxy_Config_h
-
-#include "libts.h"
-#include "ProcessManager.h"
-
-void *config_int_cb(void *data, void *value);
-void *config_long_long_cb(void *data, void *value);
-void *config_float_cb(void *data, void *value);
-void *config_string511_cb(void *data, void *value);
-void *config_string_alloc_cb(void *data, void *value);
-
-//
-// Macros that spin waiting for the data to be bound
-//
-#define SignalManager(_n,_d) pmgmt->signalManager(_n,(char*)_d)
-#define SignalWarning(_n,_s) { Warning("%s", _s); SignalManager(_n,_s); }
-
-#define RegisterMgmtCallback(_signal,_fn,_data) \
-pmgmt->registerMgmtCallback(_signal,_fn,_data)
-
-
-#define MAX_CONFIGS 100
-
-
-struct ConfigInfo
-{
- volatile int m_refcount;
-
- virtual ~ ConfigInfo()
- {
- }
-};
-
-
-class ConfigProcessor
-{
-public:
- ConfigProcessor();
-
- unsigned int set(unsigned int id, ConfigInfo * info);
- ConfigInfo *get(unsigned int id);
- void release(unsigned int id, ConfigInfo * data);
-
-public:
- ConfigInfo *infos[MAX_CONFIGS];
- int ninfos;
-};
-
-
-extern ConfigProcessor configProcessor;
-
-#endif