/usr/include/ace/TMCast/TransactionController.hpp is in libace-tmcast-dev 6.0.3+dfsg-0.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | // $Id: TransactionController.hpp 92920 2010-12-21 12:14:07Z olli $
// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_stdlib.h"
#include "ace/Synch.h"
#include "ace/Bound_Ptr.h"
#include "Protocol.hpp"
#include "Messaging.hpp"
#include <typeinfo>
namespace ACE_TMCast
{
// Messages
//
//
class Send : public virtual Message
{
public:
Send (void const* msg, size_t size)
: size_ (size)
{
ACE_OS::memcpy (payload_, msg, size_);
}
void const*
payload () const
{
return payload_;
}
size_t
size () const
{
return size_;
}
private:
size_t size_;
char payload_[Protocol::MAX_PAYLOAD_SIZE];
};
typedef
ACE_Strong_Bound_Ptr<Send, ACE_SYNCH_MUTEX>
SendPtr;
class Recv : public virtual Message
{
public:
Recv (void const* msg, size_t size)
: size_ (size)
{
ACE_OS::memcpy (payload_, msg, size_);
}
void const*
payload () const
{
return payload_;
}
size_t
size () const
{
return size_;
}
private:
size_t size_;
char payload_[Protocol::MAX_PAYLOAD_SIZE];
};
typedef
ACE_Strong_Bound_Ptr<Recv, ACE_SYNCH_MUTEX>
RecvPtr;
class Aborted : public virtual Message {};
class Commited : public virtual Message {};
//
//
//
class TransactionController
{
public:
TransactionController (MessageQueue& in,
MessageQueue& send_out,
MessageQueue& recv_out)
: trace_ (false),
voting_duration_ (0),
separation_duration_ (0),
in_ (in),
send_out_ (send_out),
recv_out_ (recv_out)
{
current_.id = 0;
current_.status = Protocol::TS_COMMITED;
}
public:
class Failure {};
void
outsync (Protocol::Transaction& c, void* payload, size_t& size)
{
if (current_.status == Protocol::TS_COMMIT ||
current_.status == Protocol::TS_ABORT)
{
if (++voting_duration_ >= Protocol::VOTING_FRAME)
{
// end of voting frame
if (current_.status == Protocol::TS_COMMIT)
{
{
if (initiated_)
{
MessageQueueAutoLock lock (send_out_);
send_out_.push (MessagePtr (new Commited));
}
else // joined transaction
{
MessageQueueAutoLock lock (recv_out_);
recv_out_.push (MessagePtr (recv_));
recv_ = RecvPtr ();
}
}
current_.status = Protocol::TS_COMMITED;
// if (trace_) cerr << "commited transaction with id "
// << current_.id << endl;
}
else // TS_ABORT
{
if (initiated_)
{
MessageQueueAutoLock lock (send_out_);
send_out_.push (MessagePtr (new Aborted));
}
else
{
// free revc_ buffer if necessary
//
if (recv_.get ()) recv_ = RecvPtr ();
}
current_.status = Protocol::TS_ABORTED;
// if (trace_) cerr << "aborted transaction with id "
// << current_.id << endl;
}
// start transaction separation frame (counts down)
// +1 because it will be decremented on this iteration
separation_duration_ = Protocol::SEPARATION_FRAME + 1;
}
}
// Set current outsync info
c.id = current_.id;
c.status = current_.status;
// Do some post-processing
switch (current_.status)
{
case Protocol::TS_COMMITED:
case Protocol::TS_ABORTED:
{
if (separation_duration_ > 0) --separation_duration_;
break;
}
case Protocol::TS_BEGIN:
{
// transfer payload
size = send_->size ();
ACE_OS::memcpy (payload, send_->payload (), size);
send_ = SendPtr ();
// get redy to vote for 'commit'
current_.status = Protocol::TS_COMMIT;
voting_duration_ = 0;
}
}
}
void
current_transaction (Protocol::Transaction const& t,
void const* payload,
size_t size)
{
Protocol::TransactionId& id = current_.id;
Protocol::TransactionStatus& s = current_.status;
if (id == 0 && t.id != 0) // catch up
{
switch (t.status)
{
case Protocol::TS_BEGIN:
case Protocol::TS_COMMIT:
case Protocol::TS_ABORT:
{
id = t.id - 1;
s = Protocol::TS_COMMITED;
break;
}
case Protocol::TS_ABORTED:
case Protocol::TS_COMMITED:
{
id = t.id;
s = t.status;
break;
}
}
// if (trace_) cerr << "caught up with id " << id << endl;
}
bool stable (s == Protocol::TS_COMMITED || s == Protocol::TS_ABORTED);
switch (t.status)
{
case Protocol::TS_BEGIN:
{
if (!stable || t.id != id + 1)
{
// Transaction is in progress or hole in transaction id's
// cerr << "unexpected request to join " << t
// << " while on " << current_ << endl;
// if (!stable) cerr << "voting progress is " << voting_duration_
// << "/" << Protocol::VOTING_FRAME << endl;
if (t.id == id) // collision
{
if (!stable && s != Protocol::TS_ABORT)
{
// abort both
// cerr << "aborting both transactions" << endl;
s = Protocol::TS_ABORT;
voting_duration_ = 0; //@@ reset voting frame
}
}
else
{
// @@ delicate case. need to think more
// cerr << "Declaring node failed." << endl;
throw Failure ();
}
}
else
{
// join the transaction
initiated_ = false;
recv_ = RecvPtr (new Recv (payload, size));
id = t.id;
s = Protocol::TS_COMMIT;
voting_duration_ = 0;
// if (trace_) cerr << "joining-for-commit transaction with id "
// << id << endl;
}
break;
}
case Protocol::TS_COMMIT:
{
if (stable && id == t.id - 1)
{
// not begin and and we haven't joined
// join for abort
initiated_ = false;
current_.id = t.id;
current_.status = Protocol::TS_ABORT;
voting_duration_ = 0;
// if (trace_) cerr << "joining-for-abort transaction with id "
// << current_.id << endl;
}
break;
}
case Protocol::TS_ABORT:
{
if ((!stable && id == t.id && s == Protocol::TS_COMMIT) ||
(stable && id == t.id - 1)) // abort current || new transaction
{
// if (trace_) cerr << "voting-for-abort on transaction with id "
// << current_.id << endl;
id = t.id;
s = Protocol::TS_ABORT;
voting_duration_ = 0; //@@ reseting voting_duration_
}
else
{
}
break;
}
case Protocol::TS_ABORTED:
case Protocol::TS_COMMITED:
{
// nothing for now
break;
}
}
}
void
api ()
{
if ((current_.status == Protocol::TS_COMMITED ||
current_.status == Protocol::TS_ABORTED) &&
separation_duration_ == 0) // no transaction in progress
{
// start new transaction
// Note that in_ is already locked by Scheduler
MessagePtr m (in_.front ());
in_.pop ();
if (typeid (*m) == typeid (Send))
{
send_ = SendPtr (m);
}
else
{
// cerr << "Expecting Send but received " << typeid (*m).name ()
// << endl;
ACE_OS::abort ();
}
current_.id++;
current_.status = Protocol::TS_BEGIN;
initiated_ = true;
// if (trace_) cerr << "starting transaction with id " << current_.id
// << endl;
}
}
private:
// FUZZ: disable check_for_ACE_Guard
typedef ACE_Guard<ACE_Thread_Mutex> AutoLock;
// FUZZ: enable check_for_ACE_Guard
bool trace_;
Protocol::Transaction current_;
bool initiated_;
unsigned short voting_duration_;
unsigned short separation_duration_;
MessageQueue& in_;
MessageQueue& send_out_;
MessageQueue& recv_out_;
SendPtr send_;
RecvPtr recv_;
};
}
|