Permalink
Browse files

Cleanup old transaction logs

  • Loading branch information...
1 parent f2fbf50 commit 5c21f0e7a296ca5ee94f64b3ad7e2db775a1ce5d @rescrv committed Jan 6, 2013
View
@@ -34,6 +34,7 @@
#include "common/hash.h"
#include "common/serialization.h"
+using hyperdex::capture_id;
using hyperdex::configuration;
using hyperdex::region_id;
using hyperdex::schema;
@@ -47,6 +48,7 @@ configuration :: configuration()
, m_region_ids_by_virtual()
, m_server_ids_by_virtual()
, m_schemas_by_region()
+ , m_capture_ids_by_region()
, m_subspace_ids_by_region()
, m_subspace_ids_for_prev()
, m_subspace_ids_for_next()
@@ -65,6 +67,7 @@ configuration :: configuration(const configuration& other)
, m_region_ids_by_virtual(other.m_region_ids_by_virtual)
, m_server_ids_by_virtual(other.m_server_ids_by_virtual)
, m_schemas_by_region(other.m_schemas_by_region)
+ , m_capture_ids_by_region(other.m_capture_ids_by_region)
, m_subspace_ids_by_region(other.m_subspace_ids_by_region)
, m_subspace_ids_for_prev(other.m_subspace_ids_for_prev)
, m_subspace_ids_for_next(other.m_subspace_ids_for_next)
@@ -201,6 +204,42 @@ configuration :: get_virtual(const region_id& ri, const server_id& si)
return virtual_server_id();
}
+bool
+configuration :: is_captured_region(const capture_id& ci) const
+{
+ for (size_t s = 0; s < m_spaces.size(); ++s)
+ {
+ for (size_t ss = 0; ss < m_spaces[s].subspaces.size(); ++ss)
+ {
+ for (size_t r = 0; r < m_spaces[s].subspaces[ss].regions.size(); ++r)
+ {
+ if (m_spaces[s].subspaces[ss].regions[r].cid == ci)
+ {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+}
+
+capture_id
+configuration :: capture_for(const region_id& ri) const
+{
+ std::vector<pair_uint64_t>::const_iterator it;
+ it = std::lower_bound(m_capture_ids_by_region.begin(),
+ m_capture_ids_by_region.end(),
+ pair_uint64_t(ri.get(), 0));
+
+ if (it != m_capture_ids_by_region.end() && it->first == ri.get())
+ {
+ return capture_id(it->second);
+ }
+
+ return capture_id();
+}
+
subspace_id
configuration :: subspace_of(const region_id& ri) const
{
@@ -447,7 +486,7 @@ configuration :: captured_regions(const server_id& si, std::vector<region_id>* s
{
for (size_t r = 0; r < m_spaces[s].subspaces[ss].regions.size(); ++r)
{
- if (!m_spaces[s].subspaces[ss].regions[r].capture)
+ if (m_spaces[s].subspaces[ss].regions[r].cid == capture_id())
{
continue;
}
@@ -671,9 +710,14 @@ configuration :: debug_dump(std::ostream& out)
for (size_t y = 0; y < ss.regions.size(); ++y)
{
region& r(ss.regions[y]);
- out << " region id=" << r.id
- << (r.capture ? " capture" : "")
- << " lower=<";
+ out << " region id=" << r.id;
+
+ if (r.cid != capture_id())
+ {
+ out << " " << r.cid;
+ }
+
+ out << " lower=<";
bool first = true;
for (size_t i = 0; i < r.lower_coord.size(); ++i)
@@ -727,6 +771,7 @@ configuration :: operator = (const configuration& rhs)
m_region_ids_by_virtual = rhs.m_region_ids_by_virtual;
m_server_ids_by_virtual = rhs.m_server_ids_by_virtual;
m_schemas_by_region = rhs.m_schemas_by_region;
+ m_capture_ids_by_region = rhs.m_capture_ids_by_region;
m_subspace_ids_by_region = rhs.m_subspace_ids_by_region;
m_subspace_ids_for_prev = rhs.m_subspace_ids_for_prev;
m_subspace_ids_for_next = rhs.m_subspace_ids_for_next;
@@ -745,6 +790,7 @@ configuration :: refill_cache()
m_region_ids_by_virtual.clear();
m_server_ids_by_virtual.clear();
m_schemas_by_region.clear();
+ m_capture_ids_by_region.clear();
m_subspace_ids_by_region.clear();
m_subspace_ids_for_prev.clear();
m_subspace_ids_for_next.clear();
@@ -779,6 +825,11 @@ configuration :: refill_cache()
m_schemas_by_region.push_back(std::make_pair(r.id.get(), &s.schema));
m_subspace_ids_by_region.push_back(std::make_pair(r.id.get(), ss.id.get()));
+ if (r.cid != capture_id())
+ {
+ m_capture_ids_by_region.push_back(std::make_pair(r.id.get(), r.cid.get()));
+ }
+
if (r.tid != transfer_id())
{
m_region_ids_by_virtual.push_back(std::make_pair(r.tvi.get(),
@@ -823,6 +874,7 @@ configuration :: refill_cache()
std::sort(m_region_ids_by_virtual.begin(), m_region_ids_by_virtual.end());
std::sort(m_server_ids_by_virtual.begin(), m_server_ids_by_virtual.end());
std::sort(m_schemas_by_region.begin(), m_schemas_by_region.end());
+ std::sort(m_capture_ids_by_region.begin(), m_capture_ids_by_region.end());
std::sort(m_subspace_ids_by_region.begin(), m_subspace_ids_by_region.end());
std::sort(m_subspace_ids_for_prev.begin(), m_subspace_ids_for_prev.end());
std::sort(m_subspace_ids_for_next.begin(), m_subspace_ids_for_next.end());
View
@@ -71,6 +71,8 @@ class configuration
const schema* get_schema(const char* space) const;
const schema* get_schema(const region_id& ri) const;
virtual_server_id get_virtual(const region_id& ri, const server_id& si);
+ bool is_captured_region(const capture_id& ci) const;
+ capture_id capture_for(const region_id& ri) const;
subspace_id subspace_of(const region_id& ri) const;
subspace_id subspace_prev(const subspace_id& ss) const;
subspace_id subspace_next(const subspace_id& ss) const;
@@ -123,6 +125,7 @@ class configuration
std::vector<pair_uint64_t> m_region_ids_by_virtual;
std::vector<pair_uint64_t> m_server_ids_by_virtual;
std::vector<uint64_schema_t> m_schemas_by_region;
+ std::vector<pair_uint64_t> m_capture_ids_by_region;
std::vector<pair_uint64_t> m_subspace_ids_by_region;
std::vector<pair_uint64_t> m_subspace_ids_for_prev;
std::vector<pair_uint64_t> m_subspace_ids_for_next;
View
@@ -350,7 +350,7 @@ region :: region()
, lower_coord()
, upper_coord()
, replicas()
- , capture(false)
+ , cid()
, tid()
, tsi()
, tvi()
@@ -362,7 +362,7 @@ region :: region(const region& other)
, lower_coord(other.lower_coord)
, upper_coord(other.upper_coord)
, replicas(other.replicas)
- , capture(other.capture)
+ , cid(other.cid)
, tid(other.tid)
, tsi(other.tsi)
, tvi(other.tvi)
@@ -380,7 +380,7 @@ region :: operator = (const region& rhs)
lower_coord = rhs.lower_coord;
upper_coord = rhs.upper_coord;
replicas = rhs.replicas;
- capture = rhs.capture;
+ cid = rhs.cid;
tid = rhs.tid;
tsi = rhs.tsi;
tvi = rhs.tvi;
@@ -392,7 +392,7 @@ hyperdex :: operator << (e::buffer::packer pa, const region& r)
{
uint16_t num_hashes = r.lower_coord.size();
uint8_t num_replicas = r.replicas.size();
- uint8_t flags = (r.capture ? 1 : 0)
+ uint8_t flags = (r.cid != capture_id() ? 1 : 0)
| (r.tid != transfer_id() ? 2 : 0);
pa = pa << r.id.get() << num_hashes << num_replicas << flags;
@@ -406,6 +406,11 @@ hyperdex :: operator << (e::buffer::packer pa, const region& r)
pa = pa << r.replicas[i];
}
+ if (r.cid != capture_id())
+ {
+ pa = pa << r.cid.get();
+ }
+
if (r.tid != transfer_id())
{
pa = pa << r.tid.get() << r.tsi.get() << r.tvi.get();
@@ -426,7 +431,6 @@ hyperdex :: operator >> (e::unpacker up, region& r)
r.lower_coord.resize(num_hashes);
r.upper_coord.resize(num_hashes);
r.replicas.resize(num_replicas);
- r.capture = flags & 1;
for (size_t i = 0; !up.error() && i < num_hashes; ++i)
{
@@ -438,6 +442,13 @@ hyperdex :: operator >> (e::unpacker up, region& r)
up = up >> r.replicas[i];
}
+ if ((flags & 1))
+ {
+ uint64_t cid;
+ up = up >> cid;
+ r.cid = capture_id(cid);
+ }
+
if ((flags & 2))
{
uint64_t tid;
View
@@ -125,7 +125,7 @@ class region
std::vector<uint64_t> lower_coord;
std::vector<uint64_t> upper_coord;
std::vector<replica> replicas;
- bool capture;
+ capture_id cid;
transfer_id tid;
server_id tsi;
virtual_server_id tvi;
@@ -30,6 +30,7 @@
#include "coordinator/initiate-transfer.h"
#include "coordinator/util.h"
+using hyperdex::capture_id;
using hyperdex::coordinator;
using hyperdex::region;
using hyperdex::region_id;
@@ -93,7 +94,8 @@ hyperdex_coordinator_initiate_transfer(struct replicant_state_machine_context* c
return generate_response(ctx, c, hyperdex::COORD_TRANSFER_IN_PROGRESS);
}
- r.capture = true;
+ r.cid = capture_id(c->counter);
+ ++c->counter;
r.tid = transfer_id(c->counter);
++c->counter;
r.tsi = sid;
@@ -31,6 +31,7 @@
#include "coordinator/util.h"
#include "coordinator/xfer-complete.h"
+using hyperdex::capture_id;
using hyperdex::coordinator;
using hyperdex::region;
using hyperdex::server_id;
@@ -74,7 +75,7 @@ hyperdex_coordinator_xfer_complete(struct replicant_state_machine_context* ctx,
if (!reg.replicas.empty() &&
reg.replicas.back().si == reg.tsi)
{
- reg.capture = false;
+ reg.cid = capture_id();
reg.tid = transfer_id();
reg.tsi = server_id();
reg.tvi = virtual_server_id();
Oops, something went wrong.

0 comments on commit 5c21f0e

Please sign in to comment.