2008-01-23 18:49:54 +00:00
|
|
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
|
|
|
// vim: ts=8 sw=2 smarttab
|
|
|
|
/*
|
|
|
|
* Ceph - scalable distributed file system
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software
|
|
|
|
* Foundation. See file COPYING.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-01-24 09:47:03 +00:00
|
|
|
#define dout(x) if (x <= g_conf.debug_ebofs) *_dout << dbeginl
|
|
|
|
|
2008-01-23 18:49:54 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include "ebofs/Ebofs.h"
|
2008-05-20 19:11:56 +00:00
|
|
|
#include "os/FileStore.h"
|
2008-01-23 18:49:54 +00:00
|
|
|
|
2008-01-25 05:59:38 +00:00
|
|
|
struct io {
|
|
|
|
utime_t start, ack, commit;
|
|
|
|
bool done() {
|
|
|
|
return ack.sec() && commit.sec();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
map<off_t,io> writes;
|
2008-01-23 18:49:54 +00:00
|
|
|
|
2008-01-25 04:38:15 +00:00
|
|
|
Mutex lock;
|
|
|
|
|
2008-01-25 05:59:38 +00:00
|
|
|
|
|
|
|
void pr(off_t off)
|
|
|
|
{
|
|
|
|
io &i = writes[off];
|
2008-04-22 20:20:38 +00:00
|
|
|
dout(2) << off << "\t"
|
2008-01-25 05:59:38 +00:00
|
|
|
<< (i.ack - i.start) << "\t"
|
|
|
|
<< (i.commit - i.start) << dendl;
|
|
|
|
writes.erase(off);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_start(off_t off, utime_t t)
|
|
|
|
{
|
|
|
|
Mutex::Locker l(lock);
|
|
|
|
writes[off].start = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_ack(off_t off, utime_t t)
|
|
|
|
{
|
|
|
|
Mutex::Locker l(lock);
|
|
|
|
writes[off].ack = t;
|
|
|
|
if (writes[off].done())
|
|
|
|
pr(off);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_commit(off_t off, utime_t t)
|
|
|
|
{
|
|
|
|
Mutex::Locker l(lock);
|
|
|
|
writes[off].commit = t;
|
|
|
|
if (writes[off].done())
|
|
|
|
pr(off);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-23 18:49:54 +00:00
|
|
|
struct C_Commit : public Context {
|
|
|
|
off_t off;
|
|
|
|
C_Commit(off_t o) : off(o) {}
|
|
|
|
void finish(int r) {
|
2008-01-25 04:38:15 +00:00
|
|
|
Mutex::Locker l(lock);
|
2008-01-25 05:59:38 +00:00
|
|
|
set_commit(off, g_clock.now());
|
2008-01-23 18:49:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
vector<const char*> args;
|
|
|
|
argv_to_vec(argc, argv, args);
|
|
|
|
parse_config_options(args);
|
|
|
|
|
|
|
|
// args
|
2008-01-24 09:47:03 +00:00
|
|
|
if (args.size() < 3) return -1;
|
2008-01-23 18:49:54 +00:00
|
|
|
const char *filename = args[0];
|
|
|
|
int seconds = atoi(args[1]);
|
|
|
|
int bytes = atoi(args[2]);
|
2008-01-24 09:47:03 +00:00
|
|
|
const char *journal = 0;
|
|
|
|
if (args.size() >= 4)
|
|
|
|
journal = args[3];
|
2008-01-23 18:49:54 +00:00
|
|
|
|
|
|
|
buffer::ptr bp(bytes);
|
|
|
|
bp.zero();
|
|
|
|
bufferlist bl;
|
|
|
|
bl.push_back(bp);
|
|
|
|
|
2008-01-25 04:38:15 +00:00
|
|
|
float interval = 1.0 / 1000;
|
|
|
|
|
2008-01-23 18:49:54 +00:00
|
|
|
cout << "#dev " << filename
|
2008-06-10 22:06:56 +00:00
|
|
|
<< ", " << seconds << " seconds, " << bytes << " bytes per write" << std::endl;
|
2008-01-23 18:49:54 +00:00
|
|
|
|
2008-03-04 05:46:23 +00:00
|
|
|
//ObjectStore *fs = new Ebofs(filename, journal);
|
2008-05-20 19:11:56 +00:00
|
|
|
ObjectStore *fs = new FileStore(filename);
|
2008-03-04 05:46:23 +00:00
|
|
|
|
|
|
|
if (g_conf.mkfs &&
|
|
|
|
fs->mkfs() < 0) {
|
2008-01-23 18:49:54 +00:00
|
|
|
cout << "mkfs failed" << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
2008-03-04 05:46:23 +00:00
|
|
|
if (fs->mount() < 0) {
|
2008-01-23 18:49:54 +00:00
|
|
|
cout << "mount failed" << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-06-10 22:06:56 +00:00
|
|
|
fs->create_collection(0);
|
|
|
|
|
2008-01-23 18:49:54 +00:00
|
|
|
utime_t now = g_clock.now();
|
|
|
|
utime_t end = now;
|
|
|
|
end += seconds;
|
|
|
|
off_t pos = 0;
|
|
|
|
//cout << "stop at " << end << std::endl;
|
|
|
|
cout << "# offset\tack\tcommit" << std::endl;
|
|
|
|
while (now < end) {
|
2008-03-04 05:46:23 +00:00
|
|
|
pobject_t poid(0, 0, object_t(1, 1));
|
2008-01-25 05:59:38 +00:00
|
|
|
utime_t start = now;
|
|
|
|
set_start(pos, now);
|
2008-04-22 20:20:38 +00:00
|
|
|
ObjectStore::Transaction t;
|
2008-05-21 18:47:48 +00:00
|
|
|
t.write(0, poid, pos, bytes, bl);
|
2008-04-22 20:20:38 +00:00
|
|
|
fs->apply_transaction(t, new C_Commit(pos));
|
2008-01-23 18:49:54 +00:00
|
|
|
now = g_clock.now();
|
2008-01-25 05:59:38 +00:00
|
|
|
set_ack(pos, now);
|
2008-01-23 18:49:54 +00:00
|
|
|
pos += bytes;
|
2008-01-25 04:38:15 +00:00
|
|
|
|
|
|
|
// wait?
|
|
|
|
utime_t next = start;
|
|
|
|
next += interval;
|
|
|
|
if (now < next) {
|
|
|
|
float s = next - now;
|
|
|
|
s *= 1000 * 1000; // s -> us
|
2008-03-04 19:06:50 +00:00
|
|
|
//cout << "sleeping for " << s << " us" << std::endl;
|
|
|
|
usleep((int)s);
|
2008-01-25 04:38:15 +00:00
|
|
|
}
|
2008-01-23 18:49:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-04 05:46:23 +00:00
|
|
|
fs->umount();
|
2008-01-23 18:49:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|