Ack. Thanks, Vu
> -----Original Message----- > From: Canh Van Truong [mailto:canh.v.tru...@dektech.com.au] > Sent: Monday, January 29, 2018 6:06 AM > To: lennart.l...@ericsson.com; vu.m.ngu...@dektech.com.au; > srinivas.mangip...@oracle.com > Cc: opensaf-devel@lists.sourceforge.net; Canh Van Truong > <canh.v.tru...@dektech.com.au> > Subject: [PATCH 1/1] log: update saflogtest to limit timeout when handling try > again [#2764] > > when saflogtest write log records and get error TRY_AGAIN in ack message, it > will handle to re-write until the error is not TRY_AGAIN. There is no limited > timeout > to handle try-again. The patch add timeout 10s for handling try-again. > --- > src/log/apitest/saflogtest.c | 86 ++++++++++++++++++++++++++++++---------- > -- > src/log/apitest/tet_LogOiOps.c | 48 +++++++++++------------ > 2 files changed, 82 insertions(+), 52 deletions(-) > > diff --git a/src/log/apitest/saflogtest.c b/src/log/apitest/saflogtest.c > index e6db5e104..160cc3b74 100644 > --- a/src/log/apitest/saflogtest.c > +++ b/src/log/apitest/saflogtest.c > @@ -21,7 +21,7 @@ > * This file contains a command line test utility to write to the SAF LOG. > * > * The main purpose of the utility is to send a burst of log messages, by > - * default not waiting for ack for each message. > + * default waiting for ack for each message. > */ > > #include <stdio.h> > @@ -42,6 +42,7 @@ > #include <poll.h> > #include <unistd.h> > #include <limits.h> > +#include "base/osaf_time.h" > #include "base/saf_error.h" > > #include <saAis.h> > @@ -55,10 +56,12 @@ > > #define MAX_NUM_STREAM 4 > > +const uint64_t kWaitTime = 10*1000; // Wait for timeout is 10 seconds > +const SaVersionT KLogVersion = {'A', 0x02, 0x03}; > + > static void logWriteLogCallbackT(SaInvocationT invocation, SaAisErrorT > error); > > static SaLogCallbacksT logCallbacks = {0, 0, logWriteLogCallbackT}; > -static SaVersionT logVersion = {'A', 0x02, 0x03}; > > static char *progname = "saflogtest"; > static SaInvocationT cb_invocation; > @@ -154,15 +157,21 @@ static SaAisErrorT write_log_record(SaLogHandleT > logHandle, > static int i = 0; > int try_agains = 0; > SaLogAckFlagsT ackflags; > + struct timespec timeout_time; > > if (wait_for_ack) > ackflags = SA_LOG_RECORD_WRITE_ACK; > else > ackflags = 0; > - > retry: > - errorCode = saLogWriteLogAsync(logStreamHandle, invocation, > ackflags, > - logRecord); > + osaf_set_millis_timeout(kWaitTime, &timeout_time); > + while (!osaf_is_timeout(&timeout_time)) { > + > + errorCode = saLogWriteLogAsync(logStreamHandle, invocation, > + ackflags, logRecord); > + if (errorCode != SA_AIS_ERR_TRY_AGAIN) break; > + osaf_nanosleep(&kHundredMilliseconds); > + } > > if (errorCode != SA_AIS_OK) { > fprintf(stderr, "saLogWriteLogAsync FAILED: %s\n", > @@ -202,9 +211,8 @@ retry: > } > > if (cb_invocation != invocation) { > - fprintf( > - stderr, > - "logWriteLogCallbackT FAILED: wrong invocation\n"); > + fprintf(stderr, "logWriteLogCallbackT FAILED:" > + " wrong invocation\n"); > return SA_AIS_ERR_BAD_OPERATION; > } > > @@ -215,17 +223,16 @@ retry: > return cb_error; > } > > - if (cb_error == SA_AIS_ERR_TRY_AGAIN) { > - usleep(100000); /* 100 ms */ > + if (cb_error == SA_AIS_ERR_TRY_AGAIN && > + !osaf_is_timeout(&timeout_time)) { > + osaf_nanosleep(&kHundredMilliseconds); > try_agains++; > goto retry; > } > > if (try_agains > 0) { > - fprintf( > - stderr, > - "\tgot %u SA_AIS_ERR_TRY_AGAIN, waited %u > secs\n", > - try_agains, try_agains / 10); > + fprintf(stderr, "\tgot %u SA_AIS_ERR_TRY_AGAIN\n", > + try_agains); > } > } > > @@ -545,7 +552,14 @@ int main(int argc, char *argv[]) > } > } > > - error = saLogInitialize(&logHandle, &logCallbacks, &logVersion); > + struct timespec timeout_time; > + osaf_set_millis_timeout(kWaitTime, &timeout_time); > + while(!osaf_is_timeout(&timeout_time)) { > + SaVersionT version = KLogVersion; > + error = saLogInitialize(&logHandle, &logCallbacks, &version); > + if (error != SA_AIS_ERR_TRY_AGAIN) break; > + osaf_nanosleep(&kHundredMilliseconds); > + } > if (error != SA_AIS_OK) { > fprintf(stderr, "saLogInitialize FAILED: %s\n", > saf_error(error)); > @@ -573,10 +587,17 @@ int main(int argc, char *argv[]) > logFileCreateAttributes_ptr = NULL; > } > > - error = saLogStreamOpen_2( > - logHandle, &stream_info[j].logStreamName, > - logFileCreateAttributes_ptr, logStreamOpenFlags, > - SA_TIME_ONE_SECOND, &logStreamHandle); > + osaf_set_millis_timeout(kWaitTime, &timeout_time); > + while(!osaf_is_timeout(&timeout_time)) { > + error = saLogStreamOpen_2( > + logHandle, &stream_info[j].logStreamName, > + logFileCreateAttributes_ptr, > + logStreamOpenFlags, > + SA_TIME_ONE_SECOND, > &logStreamHandle); > + if (error != SA_AIS_ERR_TRY_AGAIN) break; > + osaf_nanosleep(&kHundredMilliseconds); > + } > + > if (error != SA_AIS_OK) { > fprintf(stderr, "saLogStreamOpen_2 FAILED: %s\n", > saf_error(error)); > @@ -589,8 +610,13 @@ int main(int argc, char *argv[]) > write_log_record( > logHandle, logStreamHandle, selectionObject, > &stream_info[j].logRecord, wait_for_ack); > - if (interval > 0) > - usleep(interval); > + if (interval > 0) { > + struct timespec sleep_time; > + sleep_time.tv_sec = interval / 1000000; > + sleep_time.tv_nsec = > + (interval % 1000000) * 1000; > + osaf_nanosleep(&sleep_time); > + } > } > } > > @@ -617,16 +643,26 @@ int main(int argc, char *argv[]) > * closed automatically) > */ > if (stream_cnt == 1) { > - error = saLogStreamClose(logStreamHandle); > - if (SA_AIS_OK != error) { > + osaf_set_millis_timeout(kWaitTime, &timeout_time); > + while(!osaf_is_timeout(&timeout_time)) { > + error = saLogStreamClose(logStreamHandle); > + if (error != SA_AIS_ERR_TRY_AGAIN) break; > + osaf_nanosleep(&kHundredMilliseconds); > + } > + if (error != SA_AIS_OK) { > fprintf(stderr, "saLogStreamClose FAILED: %s\n", > saf_error(error)); > exit(EXIT_FAILURE); > } > } > > - error = saLogFinalize(logHandle); > - if (SA_AIS_OK != error) { > + osaf_set_millis_timeout(kWaitTime, &timeout_time); > + while(!osaf_is_timeout(&timeout_time)) { > + error = saLogFinalize(logHandle); > + if (error != SA_AIS_ERR_TRY_AGAIN) break; > + osaf_nanosleep(&kHundredMilliseconds); > + } > + if (error != SA_AIS_OK) { > fprintf(stderr, "saLogFinalize FAILED: %s\n", saf_error(error)); > exit(EXIT_FAILURE); > } > diff --git a/src/log/apitest/tet_LogOiOps.c b/src/log/apitest/tet_LogOiOps.c > index 0ee8078ad..896e993e4 100644 > --- a/src/log/apitest/tet_LogOiOps.c > +++ b/src/log/apitest/tet_LogOiOps.c > @@ -793,36 +793,32 @@ void saLogOi_28() > return; > } > > - sprintf( > - command, > - "immcfg -a saLogStreamMaxLogFileSize=2001 > safLgStrCfg=strA,safApp=safLogService"); > + sprintf(command, "immcfg -a saLogStreamMaxLogFileSize=2001 " > + "safLgStrCfg=strA,safApp=safLogService"); > rc = systemCall(command); > if (rc != 0) > goto done; > > - sprintf( > - command, > - "immcfg -a saLogStreamMaxFilesRotated=1 > safLgStrCfg=strA,safApp=safLogService"); > + sprintf(command, "immcfg -a saLogStreamMaxFilesRotated=1 " > + "safLgStrCfg=strA,safApp=safLogService"); > rc = systemCall(command); > if (rc != 0) > goto done; > > - sprintf( > - command, > - "saflogtest -b strA --count=1000 --interval=5000 \"saflogtest > (1000,5000) strA\""); > + sprintf(command, "saflogtest -b strA --count=100 --interval=5000 " > + "\"saflogtest (100,5000) strA\""); > rc = systemCall(command); > if (rc != 0) > goto done; > > - sprintf( > - command, > - "immcfg -a saLogStreamMaxFilesRotated=3 > safLgStrCfg=strA,safApp=safLogService"); > + sprintf(command, "immcfg -a saLogStreamMaxFilesRotated=3 " > + "safLgStrCfg=strA,safApp=safLogService"); > rc = systemCall(command); > > done: > /* Delete object strA */ > - sprintf(command, > - "immcfg -d safLgStrCfg=strA,safApp=safLogService 2> > /dev/null"); > + sprintf(command, "immcfg -d safLgStrCfg=strA,safApp=safLogService " > + "2> /dev/null"); > delay_ms(); > systemCall(command); > rc_validate(rc, 0); > @@ -1041,21 +1037,20 @@ void saLogOi_34() > if (rc != 0) > goto done; > > - sprintf( > - command, > - "saflogtest -b strA --count=10 --interval=10000 \"saflogtest > (10,10000) strA\""); > + sprintf(command, "saflogtest -b strA --count=10 --interval=10000 " > + "\"saflogtest (10,10000) strA\""); > rc = systemCall(command); > if (rc != 0) > goto done; > - sprintf( > - command, > - "saflogtest -b strB --count=500 --interval=5 \"saflogtest (500,5) > strB\""); > + sprintf(command, "saflogtest -b strB --count=20 --interval=5 " > + "\"saflogtest (20,5) strB\""); > + rc = systemCall(command); > if (rc != 0) > goto done; > > - sprintf( > - command, > - "saflogtest -b strC --count=700 --interval=5 \"saflogtest (700,5) > strC\""); > + sprintf(command, "saflogtest -b strC --count=30 --interval=5" > + " \"saflogtest (30,5) strC\""); > + rc = systemCall(command); > if (rc != 0) > goto done; > > @@ -1299,9 +1294,8 @@ void saLogOi_44() > if (rc != 0) > goto delete_object; > > - sprintf( > - command, > - "saflogtest -b strD --count=500 --interval=5 \"saflogtest (500,5) > strD\""); > + sprintf(command, "saflogtest -b strD --count=50 --interval=5 " > + "\"saflogtest (50,5) strD\""); > rc = systemCall(command); > > delete_object: > @@ -1428,7 +1422,7 @@ void saLogOi_50() > > while (noTimes--) { > sprintf(command, > - "saflogtest -a appTest --count=100 --interval=1 " > + "saflogtest -a appTest --count=10 --interval=1 " > "\"saflogtest (100,1,%d) appTest\"", > noTimes); > rc = system(command); > -- > 2.15.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel