Skip to content

Commit

Permalink
Debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
dacut committed Jun 16, 2016
1 parent 68529fb commit 9f1a3c6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
53 changes: 52 additions & 1 deletion c++-client/s3.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#define __STDC_FORMAT_MACROS
#include <cerrno>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <mutex>
#include <sstream>

#include <getopt.h>
Expand All @@ -28,10 +32,15 @@ using std::cout;
using std::domain_error;
using std::endl;
using std::exception;
using std::fclose;
using std::fopen;
using std::fprintf;
using std::lock_guard;
using std::map;
using std::memcpy;
using std::memmove;
using std::move;
using std::mutex;
using std::ostream;
using std::ostringstream;
using std::shared_ptr;
Expand Down Expand Up @@ -449,7 +458,8 @@ UBDS3Volume::UBDS3Volume(
m_size(0ull),
m_major(0),
m_stop_requested(false),
m_threads(thread_count)
m_threads(thread_count),
m_mutex()
{
return;
}
Expand Down Expand Up @@ -804,6 +814,21 @@ void UBDS3Volume::readBlock(
throw UBDError(message, EIO);
}

{
lock_guard<mutex> lock(m_mutex);
FILE *fp = fopen("/tmp/ubds3.audit", "a");
fprintf(fp, "readBlock %" PRIu64 "\n", block_id);
for (size_t i = 0; i < m_block_size; i += 16) {
for (size_t j = 0; j < i + 16; ++j) {
fprintf(fp, "%02x", ((unsigned char *)buffer)[j]);
}

fprintf(fp, "\n");
}

fclose(fp);
}

return;
}

Expand Down Expand Up @@ -842,12 +867,38 @@ void UBDS3Volume::writeBlock(
PutObjectRequest req;
milliseconds sleep_time(100);
String key = blockToPrefix(block_id) + m_suffix;
char *buffer2;

shared_ptr<stringstream> body(new stringstream);

body->rdbuf()->pubsetbuf(
const_cast<char *>(static_cast<char const *>(buffer)), m_block_size);

buffer2 = new char[m_block_size];
body->read(buffer2, m_block_size);

{
lock_guard<mutex> lock(m_mutex);
FILE *fp = fopen("/tmp/ubds3.audit", "a");

fprintf(fp, "writeBlock %" PRIu64 "\n", block_id);
for (size_t i = 0; i < m_block_size; i += 16) {
for (size_t j = 0; j < i + 16; ++j) {
fprintf(fp, "%02x", ((unsigned char *)buffer2)[j]);
}

fprintf(fp, "\n");
}

fclose(fp);
}
delete [] buffer2;

if (std::memcmp(buffer, buffer2, m_block_size) != 0) {
cerr << "buffer and buffer2 differ" << endl;
}
body->seekg(0);

req.SetBucket(m_bucket_name);
req.SetKey(key);
req.SetACL(m_policy);
Expand Down
5 changes: 4 additions & 1 deletion c++-client/s3.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <atomic>
#include <cstdint>
#include <mutex>
#include <string>
#include <thread>

Expand Down Expand Up @@ -70,6 +71,8 @@ public:
bool isStopRequested() { return m_stop_requested.load(); }
void requestStop() { m_stop_requested.store(true); }

std::mutex& getMutex() { return m_mutex; }

static Aws::String blockToPrefix(uint64_t block_index);

protected:
Expand Down Expand Up @@ -103,8 +106,8 @@ private:
uint64_t m_size;
uint32_t m_major;
std::atomic_bool m_stop_requested;

Aws::Utils::Array<std::thread> m_threads;
std::mutex m_mutex;
};

class UBDS3Handler {
Expand Down

0 comments on commit 9f1a3c6

Please sign in to comment.