Skip to content

Commit

Permalink
add traces
Browse files Browse the repository at this point in the history
  • Loading branch information
cktan committed Nov 20, 2019
1 parent 95ab63d commit 33f849a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 21 additions & 11 deletions client/c/s3pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ static int check_reply(char* reply, char* errmsg, int errmsgsz)


static char* chat(int port, const char* request,
char* errmsg, int errmsgsz)
char* errmsg, int errmsgsz,
FILE* trace)
{
int sockfd = -1;
struct sockaddr_in servaddr;
Expand All @@ -125,7 +126,7 @@ static char* chat(int port, const char* request,
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
snprintf(errmsg, errmsgsz, "socket: %s", strerror(errno));
snprintf(errmsg, errmsgsz, "s3pool socket: %s", strerror(errno));
goto bailout;
}
memset(&servaddr, 0, sizeof(servaddr));
Expand All @@ -137,7 +138,7 @@ static char* chat(int port, const char* request,

// connect the client socket to server socket
if (connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) != 0) {
snprintf(errmsg, errmsgsz, "connect: %s", strerror(errno));
snprintf(errmsg, errmsgsz, "s3pool connect: %s", strerror(errno));
goto bailout;
}

Expand All @@ -156,7 +157,7 @@ static char* chat(int port, const char* request,
if (newsz == 0) newsz = 1024;
char* t = realloc(reply, newsz);
if (!t) {
snprintf(errmsg, errmsgsz, "read: reply message too big -- out of memory");
snprintf(errmsg, errmsgsz, "s3pool read: reply message too big -- out of memory");
goto bailout;
}
p = t + (p - reply);
Expand All @@ -170,7 +171,7 @@ static char* chat(int port, const char* request,
if (n == -1) {
if (errno == EAGAIN) continue;

snprintf(errmsg, errmsgsz, "read: %s", strerror(errno));
snprintf(errmsg, errmsgsz, "s3pool read: %s", strerror(errno));
goto bailout;
}
if (n == 0) break;
Expand All @@ -181,13 +182,18 @@ static char* chat(int port, const char* request,

close(sockfd);

if (trace) {
fprintf(trace, "\nSEND: %s\nRECEIVED: %s\n", request, reply);
}

if (-1 == check_reply(reply, errmsg, errmsgsz)) {
goto bailout;
}

char* aptr = strdup(reply+3);
/* reply must contain "OK\nPAYLOAD\n" verified by check_reply() above */
char* aptr = strdup(reply+3); /* skip to PAYLOAD */
if (!aptr) {
snprintf(errmsg, errmsgsz, "%s", "out of memory");
snprintf(errmsg, errmsgsz, "s3pool: out of memory");
goto bailout;
}

Expand Down Expand Up @@ -236,7 +242,11 @@ char* s3pool_pull_ex(int port, const char* bucket,
goto bailout;
}

reply = chat(port, request, errmsg, errmsgsz);
char fname[100];
sprintf(fname, "/tmp/s3pool.%d.log", getpid());
FILE* fp = fopen(fname, "a");
reply = chat(port, request, errmsg, errmsgsz, fp);
fclose(fp);
if (! reply) {
goto bailout;
}
Expand Down Expand Up @@ -278,7 +288,7 @@ int s3pool_push(int port, const char* bucket, const char* key, const char* fpath
goto bailout;
}

reply = chat(port, request, errmsg, errmsgsz);
reply = chat(port, request, errmsg, errmsgsz, 0);
if (! reply) {
goto bailout;
}
Expand Down Expand Up @@ -309,7 +319,7 @@ int s3pool_refresh(int port, const char* bucket,
goto bailout;
}

reply = chat(port, request, errmsg, errmsgsz);
reply = chat(port, request, errmsg, errmsgsz, 0);
if (! reply) {
goto bailout;
}
Expand Down Expand Up @@ -346,7 +356,7 @@ char* s3pool_glob(int port, const char* bucket, const char* pattern,
if (!request) {
goto bailout;
}
reply = chat(port, request, errmsg, errmsgsz);
reply = chat(port, request, errmsg, errmsgsz, 0);
if (! reply) {
goto bailout;
}
Expand Down
2 changes: 1 addition & 1 deletion src/s3pool/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package conf

var VerboseLevel = 0
var VerboseLevel = 1
var RefreshInterval = 15 // in minutes
var BucketmonChannel chan<- string

Expand Down

0 comments on commit 33f849a

Please sign in to comment.