Commit 17f9a63b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 81049e5d
......@@ -163,7 +163,23 @@ error _Conn::_pinner(context::Context ctx) {
_Conn& wconn = *this;
xerr::Contextf E("pinner"); // NOTE pinner error goes to Conn::close who has its own context
for (int i=0; i <10; i++)
xlog::Fatalf("Hello from pinner! %d %s", i, "qqq zzz");
error err = wconn.__pinner(ctx);
err = E(err);
// if pinner fails, wcfs will kill us.
// log pinner error so the error is not hidden.
// print to stderr as well as by default log does not print to there.
// XXX also catch panic/exc ?
if (!(err == nil || errors::Is(err, context::canceled))) { // canceled = .close asks pinner to stop
xlog::Fatalf("CRITICAL: %s", v(err));
xlog::Fatalf("CRITICAL: wcfs server will likely kill us soon.");
fprintf(stderr, "CRITICAL: %s\n", v(err));
fprintf(stderr, "CRITICAL: wcfs server will likely kill us soon.\n");
}
// mark the connection non-operational if the pinner fails
wconn._downMu.lock();
......@@ -173,28 +189,12 @@ error _Conn::_pinner(context::Context ctx) {
}
wconn._downMu.unlock();
return E(err);
return err;
}
error _Conn::__pinner(context::Context ctx) {
_Conn& wconn = *this;
// XXX panic/exc -> log.CRITICAL
#if 0
// if pinner fails, wcfs will kill us.
// log pinner exception so the error is not hidden.
// print to stderr as well as by default log does not print to there.
def _():
exc = sys.exc_info()[1]
if exc in (None, context.canceled): # canceled = .close asks pinner to stop
return
log.critical('pinner failed:', exc_info=1)
print('CRITICAL: pinner failed:', file=sys.stderr)
traceback.print_exc(file=sys.stderr)
print('\nCRITICAL: wcfs server will likely kill us soon.', file=sys.stderr)
defer(_)
#endif
PinReq req;
error err;
......
......@@ -241,6 +241,43 @@ error Contextf::operator() (error err) const {
} // xerr::
#include <golang/time.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/syscall.h>
// xlog::
namespace xlog {
void __Logf(const char *file, int line, char level, const char *format, ...) {
double t = time::now();
time_t t_int = time_t(t);
struct tm tm_loc;
localtime_r(&t_int, &tm_loc);
char t_buf[32];
strftime(t_buf, sizeof(t_buf), "%m%d %H:%M:%S", &tm_loc);
int t_us = int((t-t_int)*1E6);
pid_t tid = syscall(SYS_gettid);
string prefix = fmt::sprintf("%c%s.%06d %d %s:%d] ", level, t_buf, t_us, tid, file, line);
// XXX better to emit prefix and msg in one go.
fprintf(stderr, "%s", v(prefix));
va_list argp;
va_start(argp, format);
vfprintf(stderr, format, argp);
va_end(argp);
fprintf(stderr, "\n");
}
} // xlog
// wcfs::
namespace wcfs {
......@@ -252,7 +289,7 @@ static string h016(uint64_t v) { return fmt::sprintf("%016lx", v); }
template<> string v_(zodb::Tid tid) { return h016(tid); }
//template<> string v_(zodb::Oid oid) { return h016(oid); }
// XXX Tid and Oid are typedefs for uint64_t and C++ reduces template
// specializations to theunderlying type. This providing specialization for
// specializations to the underlying type. This providing specialization for
// both Tid and Oid results in "multiple definition" error.
} // wcfs::
......@@ -168,6 +168,15 @@ public:
} // xerr::
// xlog::
namespace xlog {
#define Fatalf(format, ...) __Logf(__FILE__, __LINE__, 'F', format, ##__VA_ARGS__)
void __Logf(const char *file, int line, char level, const char *format, ...);
} // xlog::
// wcfs::
namespace wcfs {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment