diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-06-27 16:27:24 -0400 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-06-27 16:27:24 -0400 |
commit | 85a70987f18610fb4d4eac2eded8155a9b2a6031 (patch) | |
tree | bba146de64978f6804149bfe524c53f6b5c0bc97 /cpp/src/Freeze/TransactionalEvictorContext.cpp | |
parent | minor edits (diff) | |
download | ice-85a70987f18610fb4d4eac2eded8155a9b2a6031.tar.bz2 ice-85a70987f18610fb4d4eac2eded8155a9b2a6031.tar.xz ice-85a70987f18610fb4d4eac2eded8155a9b2a6031.zip |
Freeze transaction attributes + new Freeze/casino demo
Diffstat (limited to 'cpp/src/Freeze/TransactionalEvictorContext.cpp')
-rw-r--r-- | cpp/src/Freeze/TransactionalEvictorContext.cpp | 132 |
1 files changed, 83 insertions, 49 deletions
diff --git a/cpp/src/Freeze/TransactionalEvictorContext.cpp b/cpp/src/Freeze/TransactionalEvictorContext.cpp index 4c40321a8a1..395203ed805 100644 --- a/cpp/src/Freeze/TransactionalEvictorContext.cpp +++ b/cpp/src/Freeze/TransactionalEvictorContext.cpp @@ -81,15 +81,15 @@ Freeze::TransactionalEvictorContext::postCompletion(bool committed, bool deadloc } } -Freeze::TransactionalEvictorContext::ServantHolder* -Freeze::TransactionalEvictorContext::findServantHolder(const Identity& ident, ObjectStore<TransactionalEvictorElement>* store) const +Freeze::TransactionalEvictorContext::ServantHolder::Body* +Freeze::TransactionalEvictorContext::findServantHolderBody(const Identity& ident, ObjectStore<TransactionalEvictorElement>* store) const { for(Stack::const_iterator p = _stack.begin(); p != _stack.end(); ++p) { - ServantHolder* sh = *p; - if(sh->matches(ident, store)) + ServantHolder::Body* b = *p; + if(b->matches(ident, store)) { - return sh; + return b; } } return 0; @@ -165,11 +165,11 @@ Freeze::TransactionalEvictorContext::servantRemoved(const Identity& ident, // // Lookup servant holder on stack // - ServantHolder* sh = findServantHolder(ident, store); - if(sh != 0) + ServantHolder::Body* body = findServantHolderBody(ident, store); + if(body != 0) { - sh->removed(); - return sh->servant(); + body->removed = true; + return body->rec.servant; } else { @@ -197,24 +197,55 @@ Freeze::TransactionalEvictorContext::deadlockException() // ServantHolder // -Freeze::TransactionalEvictorContext::ServantHolder::ServantHolder(const TransactionalEvictorContextPtr& ctx, - const Current& current, - ObjectStore<TransactionalEvictorElement>* store, - bool useNonmutating) : - _readOnly(false), - _ownServant(false), - _removed(false), - _ctx(ctx), - _current(current), - _store(store) +Freeze::TransactionalEvictorContext::ServantHolder::ServantHolder() : + _ownBody(true) { - ServantHolder* sh = ctx->findServantHolder(_current.id, _store); +} + + +Freeze::TransactionalEvictorContext::ServantHolder::~ServantHolder() +{ + if(_ownBody && _body.ownServant) + { + const TransactionalEvictorContextPtr& ctx = *(_body.ctx); - if(sh != 0) + if(ctx->_tx != 0) + { + if(!_body.readOnly && !_body.removed) + { + EvictorIBase::updateStats(_body.rec.stats, IceUtil::Time::now().toMilliSeconds()); + _body.store->update(_body.current->id, _body.rec, ctx->_tx); + } + + if(!_body.readOnly || _body.removed) + { + ctx->_invalidateList.push_back(new ToInvalidate(_body.current->id, _body.store)); + } + } + ctx->_stack.pop_front(); + } +} + + +void +Freeze::TransactionalEvictorContext::ServantHolder::init(const TransactionalEvictorContextPtr& ctx, + const Current& current, + ObjectStore<TransactionalEvictorElement>* store) +{ + assert(_ownBody && _body.ctx == 0); + + _body.ctx = &ctx; + _body.current = ¤t; + _body.store = store; + + ServantHolder::Body* body = ctx->findServantHolderBody(current.id, store); + + if(body != 0) { - if(!sh->_removed) + if(!body->removed) { - _rec = sh->_rec; + _body.rec = body->rec; + _body.readOnly = body->readOnly; } } else @@ -222,46 +253,49 @@ Freeze::TransactionalEvictorContext::ServantHolder::ServantHolder(const Transact // // Let's load this servant // - if(store->load(current.id, ctx->_tx, _rec)) + if(store->load(current.id, ctx->_tx, _body.rec)) { - _ctx->_stack.push_front(this); - _ownServant = true; - - // - // Compute readonly properly - // - _readOnly = (useNonmutating && current.mode == Nonmutating) || - (!useNonmutating && (_rec.servant->ice_operationAttributes(current.operation) & 0x1) == 0); + ctx->_stack.push_front(&_body); + _body.ownServant = true; } } } +void +Freeze::TransactionalEvictorContext::ServantHolder::adopt(ServantHolder& other) +{ + assert(_ownBody && _body.ctx == 0); -Freeze::TransactionalEvictorContext::ServantHolder::~ServantHolder() + _body = other._body; + other._ownBody = false; +} + +void +Freeze::TransactionalEvictorContext::ServantHolder::markReadWrite() { - if(_ownServant) + assert(_ownBody); + + if(_body.ownServant) { - if(_ctx->_tx != 0) + _body.readOnly = false; + } + else + { + if(_body.readOnly) { - if(!_readOnly && !_removed) - { - EvictorIBase::updateStats(_rec.stats, IceUtil::Time::now().toMilliSeconds()); - _store->update(_current.id, _rec, _ctx->_tx); - } - - if(!_readOnly || _removed) - { - _ctx->_invalidateList.push_back(new ToInvalidate(_current.id, _store)); - } + throw DatabaseException(__FILE__, __LINE__, "freeze:write operation called from freeze:read operation"); } - _ctx->_stack.pop_front(); } } -void -Freeze::TransactionalEvictorContext::ServantHolder::removed() +Freeze::TransactionalEvictorContext::ServantHolder::Body::Body() : + readOnly(true), + removed(false), + ownServant(false), + ctx(0), + current(0), + store(0) { - _removed = true; } // |