From 9358729d8712edf6445a9e186628d11df7fc4f1a Mon Sep 17 00:00:00 2001
From: amichelo <andrea.michelotti@lnf.infn.it>
Date: Fri, 24 Aug 2018 17:35:37 +0200
Subject: [PATCH] resolved another mismatch new/free, fixed string len in
 burst_tag, enhanced debug print of messages added stop service

---
 .../api/control_unit/SendStorageBurst.cpp     |  2 ++
 .../cache_system/CouchbaseCacheDriver.cpp     |  2 +-
 .../cache_system/CouchbaseCacheDriver.h       |  2 +-
 chaos/common/data/CDataWrapper.h              |  4 +--
 chaos/common/data/cache/AttributeValue.cpp    |  2 +-
 .../message/MultiAddressMessageChannel.cpp    |  9 +++---
 chaos/common/metric/MetricCollector.cpp       |  5 +++-
 .../control_manager/AbstractControlUnit.cpp   |  7 +++--
 tools/chaos_services.sh                       |  6 ++--
 tools/common_util.sh                          | 29 +++++++++++++------
 tools/generateGoogleProfilePdf.sh             |  5 ++++
 11 files changed, 49 insertions(+), 24 deletions(-)

diff --git a/ChaosMetadataService/api/control_unit/SendStorageBurst.cpp b/ChaosMetadataService/api/control_unit/SendStorageBurst.cpp
index fc934e43f..6dcf9ff84 100644
--- a/ChaosMetadataService/api/control_unit/SendStorageBurst.cpp
+++ b/ChaosMetadataService/api/control_unit/SendStorageBurst.cpp
@@ -95,6 +95,8 @@ CDataWrapper *SendStorageBurst::execute(CDataWrapper *api_data,
         batch_data->addStringValue(chaos::RpcActionDefinitionKey::CS_CMDM_ACTION_NAME, chaos::ControlUnitNodeDomainAndActionRPC::ACTION_STORAGE_BURST);
         batch_data->addCSDataValue(chaos::RpcActionDefinitionKey::CS_CMDM_ACTION_MESSAGE, *burst_ser);
         //launch the batch command
+        CU_RNU_DBG<<"Sending Command:"<<batch_data->getCompliantJSONString();
+
         command_id = getBatchExecutor()->submitCommand(std::string(GET_MDS_COMMAND_ALIAS(batch::node::SendRpcCommand)),
                                                        batch_data.release());
     }
diff --git a/ChaosMetadataService/cache_system/CouchbaseCacheDriver.cpp b/ChaosMetadataService/cache_system/CouchbaseCacheDriver.cpp
index ec97fc699..8c5068fda 100644
--- a/ChaosMetadataService/cache_system/CouchbaseCacheDriver.cpp
+++ b/ChaosMetadataService/cache_system/CouchbaseCacheDriver.cpp
@@ -315,7 +315,7 @@ int CouchbaseCacheDriver::updateConfig() {
         CCDLDBG_ << "session params:"<<create_options.v.v3.connstr;
     }
     
-    lcb_U32 newval = 2000000; // Set to 4 seconds
+    lcb_U32 newval = COUCHBASE_DEFAULT_TIMEOUT; 
     if((last_err=lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_OP_TIMEOUT, &newval))!=LCB_SUCCESS){
         CCDLERR_<< "Cannot set OP Timeout -> " << lcb_strerror(NULL, last_err);
         return -2;
diff --git a/ChaosMetadataService/cache_system/CouchbaseCacheDriver.h b/ChaosMetadataService/cache_system/CouchbaseCacheDriver.h
index b4d42efa5..e4d39ced6 100644
--- a/ChaosMetadataService/cache_system/CouchbaseCacheDriver.h
+++ b/ChaosMetadataService/cache_system/CouchbaseCacheDriver.h
@@ -32,7 +32,7 @@
 
 #include <boost/lockfree/queue.hpp>
 #include <boost/thread.hpp>
-
+#define COUCHBASE_DEFAULT_TIMEOUT 5000000
 namespace chaos {
     namespace data_service {
         namespace cache_system {
diff --git a/chaos/common/data/CDataWrapper.h b/chaos/common/data/CDataWrapper.h
index ed8bfcb8d..81b0ed980 100644
--- a/chaos/common/data/CDataWrapper.h
+++ b/chaos/common/data/CDataWrapper.h
@@ -61,12 +61,12 @@ namespace chaos {
                     buffer = 0L;
                     disposeOnDelete = true;
                     if(iBuff && iSize){
-                        buffer = (char*)malloc(iSize);
+                        buffer = (char*)new char[iSize];
                         std::memcpy(buffer, iBuff, iSize);
                     }
                 }
                 ~SerializationBuffer(){
-                    if(disposeOnDelete && buffer) free(buffer);
+                    if(disposeOnDelete && buffer) delete [](buffer);
                 }
                 size_t getBufferLen(){return bSize;};
                 const char *getBufferPtr(){return buffer;};
diff --git a/chaos/common/data/cache/AttributeValue.cpp b/chaos/common/data/cache/AttributeValue.cpp
index eb6657f7f..80f1296cf 100644
--- a/chaos/common/data/cache/AttributeValue.cpp
+++ b/chaos/common/data/cache/AttributeValue.cpp
@@ -123,7 +123,7 @@ bool AttributeValue::setStringValue(const std::string& value,
     CHAOS_ASSERT(value_buffer)
     std::strncpy(static_cast<char*>(value_buffer),
                  value.c_str(),
-                 size-1);
+                 size);
     return true;
 }
 
diff --git a/chaos/common/message/MultiAddressMessageChannel.cpp b/chaos/common/message/MultiAddressMessageChannel.cpp
index 0646d83d1..94e872e6c 100644
--- a/chaos/common/message/MultiAddressMessageChannel.cpp
+++ b/chaos/common/message/MultiAddressMessageChannel.cpp
@@ -154,12 +154,12 @@ void MultiAddressMessageChannel::sendMessage(const std::string& action_domain,
                                              CDataWrapper *message_pack,
                                              bool on_this_thread) {
     MMCFeederService *service =  static_cast<MMCFeederService*>(service_feeder.getService());
-    if(service) {
+    if(service ) {
         MessageChannel::sendMessage(service->ip_port,
                                     action_domain,
                                     action_name,
                                     message_pack);
-        DEBUG_CODE(MAMC_DBG << "Sent message to:" << service->ip_port;)
+        DEBUG_CODE(MAMC_DBG << "Sent message dom:'"<<action_domain<<"' action:'"<<action_name<<"' port:'" << service->ip_port<<"'" " msg:"<<(message_pack?message_pack->getCompliantJSONString():"NULL");)
     }
     
 }
@@ -172,12 +172,13 @@ ChaosUniquePtr<MessageRequestFuture> MultiAddressMessageChannel::_sendRequestWit
     ChaosUniquePtr<MessageRequestFuture> result;
     MMCFeederService *service =  static_cast<MMCFeederService*>(service_feeder.getService());
     bool has_been_found_a_server = (service!=NULL);
-    if(has_been_found_a_server) {
+    if(has_been_found_a_server ) {
         result = MessageChannel::sendRequestWithFuture((used_remote_address = service->ip_port),
                                                        action_domain,
                                                        action_name,
                                                        request_pack);
-        DEBUG_CODE(MAMC_DBG << "Sent request to:" << used_remote_address;)
+        DEBUG_CODE(MAMC_DBG << "Sent Future message dom:'"<<action_domain<<"' action:'"<<action_name<<"' port:'" << service->ip_port<<"'" " msg:"<<(request_pack?request_pack->getCompliantJSONString():"NULL");)
+
     } else {
         used_remote_address.clear();
     }
diff --git a/chaos/common/metric/MetricCollector.cpp b/chaos/common/metric/MetricCollector.cpp
index afd76a61d..099a59b16 100644
--- a/chaos/common/metric/MetricCollector.cpp
+++ b/chaos/common/metric/MetricCollector.cpp
@@ -57,7 +57,10 @@ stat_intervall(update_time_in_sec*1000){
     }
     if(!on_console &&
        !on_file) {
-        throw CException(-1, "No metric backdend selected for collector", __PRETTY_FUNCTION__);
+           MC_INFO<< "% No metric output selected for collector, redirecting to default. To redirect output use options:'"<<InitOption::OPT_LOG_METRIC_ON_FILE<<"' and '"<<InitOption::OPT_LOG_METRIC_ON_FILE_PATH<<"'" ;
+        addBackend(metric::MetricBackendPointer(new metric::ConsoleMetricBackend(collector_name)));
+        // per una cavolata non parte l'MDS
+        //throw CException(-1, "No metric output selected for collector", __PRETTY_FUNCTION__);
     }
 }
 
diff --git a/chaos/cu_toolkit/control_manager/AbstractControlUnit.cpp b/chaos/cu_toolkit/control_manager/AbstractControlUnit.cpp
index e95417713..6bb3cba42 100644
--- a/chaos/cu_toolkit/control_manager/AbstractControlUnit.cpp
+++ b/chaos/cu_toolkit/control_manager/AbstractControlUnit.cpp
@@ -369,7 +369,7 @@ void AbstractControlUnit::_defineActionAndDataset(CDataWrapper& setup_configurat
                                                                           &AbstractControlUnit::_submitStorageBurst,
                                                                           ControlUnitNodeDomainAndActionRPC::ACTION_STORAGE_BURST,
                                                                           "Execute a storage burst on control unit");
-    action_description->addParam(ControlUnitNodeDefinitionKey::CONTROL_UNIT_DATASET_HISTORY_BURST_TAG, DataType::TYPE_STRING, "Tag asosciated to the stored data during burst");
+    action_description->addParam(ControlUnitNodeDefinitionKey::CONTROL_UNIT_DATASET_HISTORY_BURST_TAG, DataType::TYPE_STRING, "Tag associated to the stored data during burst");
     action_description->addParam(ControlUnitNodeDefinitionKey::CONTROL_UNIT_DATASET_HISTORY_BURST_TYPE, DataType::TYPE_INT32, "The type of burst");
     action_description->addParam(ControlUnitNodeDefinitionKey::CONTROL_UNIT_DATASET_HISTORY_BURST_VALUE, DataType::TYPE_UNDEFINED, "The value of the burst is defined by the type");
     
@@ -1473,7 +1473,7 @@ chaos::common::data::CDataWrapper* AbstractControlUnit::_submitStorageBurst(CDat
         ACULERR_ << CHAOS_FORMAT("The value is mandatory for burst %1%", %data->getJSONString());
         return NULL;
     }
-    
+    ACULDBG_<<"Enabling burst:"<<data->getCompliantJSONString();
     LQueueBurstWriteLock wl = burst_queue.getWriteLockObject();
     burst_queue().push(burst);
     return NULL;
@@ -2025,6 +2025,7 @@ void AbstractControlUnit::manageBurstQueue() {
             }
             burst_queue().pop();
             //set the tag for burst
+            ACULDBG_<<"===Start Burst tag:'"<<current_burst->dataset_burst->tag<<"' ====";
             key_data_storage->addTag(current_burst->dataset_burst->tag);
             key_data_storage->setTimingConfigurationBehaviour(false);
             key_data_storage->setOverrideStorageType(DataServiceNodeDefinitionType::DSStorageTypeHistory);
@@ -2037,6 +2038,8 @@ void AbstractControlUnit::manageBurstQueue() {
         
         if(!current_burst->active(timestamp_acq_cached_value->getValuePtr<int64_t>())) {
             //remove the tag for the burst
+            ACULDBG_<<"=== End Burst tag:'"<<current_burst->dataset_burst->tag<<"'  =======";
+
             key_data_storage->removeTag(current_burst->dataset_burst->tag);
             key_data_storage->setTimingConfigurationBehaviour(true);
             key_data_storage->setOverrideStorageType(DataServiceNodeDefinitionType::DSStorageTypeUndefined);
diff --git a/tools/chaos_services.sh b/tools/chaos_services.sh
index 2ad8740ff..06c68b8a5 100755
--- a/tools/chaos_services.sh
+++ b/tools/chaos_services.sh
@@ -72,7 +72,7 @@ start_mds(){
     else
         info_mesg "starting MDS..." "($CHAOS_LIVE_SERVERS)($CHAOS_DB_SERVERS)"
         
-        run_proc "$CHAOS_PREFIX/bin/$MDS_EXEC --conf-file $CHAOS_PREFIX/etc/mds.cfg $CHAOS_OVERALL_OPT $CHAOS_MDS_OPT --log-file $CHAOS_PREFIX/log/$MDS_EXEC.$MYPID.log > $CHAOS_PREFIX/log/$MDS_EXEC.$MYPID.std.out 2>&1 &" "$MDS_EXEC"
+        run_proc "$CHAOS_SERVICE_ENV $CHAOS_PREFIX/bin/$MDS_EXEC --conf-file $CHAOS_PREFIX/etc/mds.cfg $CHAOS_OVERALL_OPT $CHAOS_MDS_OPT --log-file $CHAOS_PREFIX/log/$MDS_EXEC.$MYPID.log > $CHAOS_PREFIX/log/$MDS_EXEC.$MYPID.std.out 2>&1 &" "$MDS_EXEC"
         #    echo "$CHAOS_PREFIX/bin/$MDS_EXEC --conf-file $CHAOS_PREFIX/etc/mds.cfg $CHAOS_OVERALL_OPT $CHAOS_MDS_OPT --log-file $CHAOS_PREFIX/log/$MDS_EXEC.log" >> $CHAOS_PREFIX/log/$MDS_EXEC.std.out
         
         if execute_command_until_ok "grep \"Data Service published\" $CHAOS_PREFIX/log/$MDS_EXEC.$MYPID.log" 120;then
@@ -104,7 +104,7 @@ start_ui(){
         info_mesg "starting " "webui.."
         # check_proc_then_kill "$CHAOS_PREFIX/bin/$UI_EXEC"
         
-        run_proc "$CHAOS_PREFIX/bin/$UI_EXEC --conf-file $CHAOS_PREFIX/etc/webui.cfg $port $CHAOS_OVERALL_OPT --log-file $CHAOS_PREFIX/log/webui.$MYPID.log > $CHAOS_PREFIX/log/$UI_EXEC.$MYPID.std.out 2>&1 &" "$UI_EXEC"
+        run_proc "$CHAOS_SERVICE_ENV $CHAOS_PREFIX/bin/$UI_EXEC --conf-file $CHAOS_PREFIX/etc/webui.cfg $port $CHAOS_OVERALL_OPT --log-file $CHAOS_PREFIX/log/webui.$MYPID.log > $CHAOS_PREFIX/log/$UI_EXEC.$MYPID.std.out 2>&1 &" "$UI_EXEC"
     fi
     #   echo "$CHAOS_PREFIX/bin/$UI_EXEC --conf-file $CHAOS_PREFIX/etc/webui.cfg $port $CHAOS_OVERALL_OPT --log-file $CHAOS_PREFIX/log/webui.log" >> $CHAOS_PREFIX/log/$UI_EXEC.std.out
 }
@@ -115,7 +115,7 @@ start_agent(){
         
     else
         info_mesg "starting " "agent"
-        run_proc "$CHAOS_PREFIX/bin/$AGENT_EXEC --conf-file  $CHAOS_PREFIX/etc/agent.cfg $CHAOS_OVERALL_OPT --log-on-file --log-file $CHAOS_PREFIX/log/agent.$MYPID.log > $CHAOS_PREFIX/log/$AGENT_EXEC.$MYPID.std.out 2>&1 &" "$AGENT_EXEC"
+        run_proc "$CHAOS_SERVICE_ENV $CHAOS_PREFIX/bin/$AGENT_EXEC --conf-file  $CHAOS_PREFIX/etc/agent.cfg $CHAOS_OVERALL_OPT --log-on-file --log-file $CHAOS_PREFIX/log/agent.$MYPID.log > $CHAOS_PREFIX/log/$AGENT_EXEC.$MYPID.std.out 2>&1 &" "$AGENT_EXEC"
     fi
 }
 
diff --git a/tools/common_util.sh b/tools/common_util.sh
index a3cd5604d..144ec5c8f 100644
--- a/tools/common_util.sh
+++ b/tools/common_util.sh
@@ -12,8 +12,11 @@ export LC_ALL="en_US.UTF-8"
 export CHAOS_OVERALL_OPT="--event-disable 1 --log-max-size 200"
 export CHAOS_MDS_OPT=""
 export CHAOS_DEBUG_CMD=""
-export CHAOS_RUN_ENV="" ## envirnoment to apply to run appliction i.e checkers
+## CHAOS_RUN_ENV="" ## environment to apply to run appliction i.e checkers
+## CHAOS_SERVICE_ENV ## environment to apply to services (mds,webui,agent)
 export CHAOS_EXTERNAL_MDS=""
+
+
 if [ -n "$CHAOS_DEBUG_CMD_TOOL" ];then
     CHAOS_DEBUG_CMD=$CHAOS_DEBUG_CMD_TOOL
 fi
@@ -537,26 +540,34 @@ test_services(){
 	return 1
     fi
 }
-start_services(){
-
-    if $tools/chaos_services.sh start mds; then
-	ok_mesg "chaos start MDS/CDS"
+services(){
+	command_line="$1"
+	if $tools/chaos_services.sh $command_line mds; then
+	ok_mesg "chaos $command_line MDS/CDS"
 
     else
-	nok_mesg "chaos start MDS/CDS"
+	nok_mesg "chaos $command_line MDS/CDS"
 	return 1
     fi
 
     
-    if $tools/chaos_services.sh start webui; then
-	ok_mesg "chaos start WEBUI, sleeping 10s"
+    if $tools/chaos_services.sh $command_line webui; then
+	ok_mesg "chaos $command_line WEBUI, sleeping 10s"
 	sleep 10
     else
-	nok_mesg "chaos start WEBUI"
+	nok_mesg "chaos $command_line WEBUI"
 	return 1
     fi
     return 0
 }
+stop_services(){
+	services "stop"
+}
+
+start_services(){
+	services "start"
+    
+}
 start_mds(){
     if $tools/chaos_services.sh start mds; then
 	ok_mesg "chaos start mds"
diff --git a/tools/generateGoogleProfilePdf.sh b/tools/generateGoogleProfilePdf.sh
index 83f1b9d50..b43d50b41 100755
--- a/tools/generateGoogleProfilePdf.sh
+++ b/tools/generateGoogleProfilePdf.sh
@@ -17,5 +17,10 @@ for heapf in $heapls;do
 	else
 	    echo "## error processing $heapf"
 	fi
+	if google-pprof $2/$pname "$heapf" --inuse_objects --lines --heapcheck  --edgefraction=1e-10 --nodefraction=1e-10 --web > $pname.$ppid.svg;then
+	    echo "* generated $pname.$ppid.svg"
+	else
+	    echo "## error processing $heapf"
+	fi
     fi
 done
-- 
GitLab