summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/EvictorIteratorI.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2004-04-09 23:21:15 +0000
committerBernard Normier <bernard@zeroc.com>2004-04-09 23:21:15 +0000
commit0dcad3e212de5e8560e57c1a3d2f04909ebe7513 (patch)
tree412366d59303c0c4a90d281e50f78c39775db31d /cpp/src/Freeze/EvictorIteratorI.cpp
parentEach request now has its own set of object factories. (diff)
downloadice-0dcad3e212de5e8560e57c1a3d2f04909ebe7513.tar.bz2
ice-0dcad3e212de5e8560e57c1a3d2f04909ebe7513.tar.xz
ice-0dcad3e212de5e8560e57c1a3d2f04909ebe7513.zip
Updated Freeze Evictor with new facets
Diffstat (limited to 'cpp/src/Freeze/EvictorIteratorI.cpp')
-rw-r--r--cpp/src/Freeze/EvictorIteratorI.cpp108
1 files changed, 47 insertions, 61 deletions
diff --git a/cpp/src/Freeze/EvictorIteratorI.cpp b/cpp/src/Freeze/EvictorIteratorI.cpp
index 346301f0148..c5062d8cb50 100644
--- a/cpp/src/Freeze/EvictorIteratorI.cpp
+++ b/cpp/src/Freeze/EvictorIteratorI.cpp
@@ -1,6 +1,6 @@
// **********************************************************************
//
-// Copyright (c) 2003
+// Copyright (c) 2003-2004
// ZeroC, Inc.
// Billerica, MA, USA
//
@@ -13,6 +13,7 @@
// **********************************************************************
#include <Freeze/EvictorIteratorI.h>
+#include <Freeze/ObjectStore.h>
#include <Freeze/EvictorI.h>
#include <Freeze/Util.h>
@@ -21,17 +22,13 @@ using namespace Freeze;
using namespace Ice;
-Freeze::EvictorIteratorI::EvictorIteratorI(EvictorI& evictor, Int batchSize, bool loadServants) :
- _evictor(evictor),
+Freeze::EvictorIteratorI::EvictorIteratorI(ObjectStore* store, Int batchSize) :
+ _store(store),
_batchSize(static_cast<size_t>(batchSize)),
- _loadServants(loadServants),
_key(1024),
- _more(true)
+ _more(store != 0),
+ _initialized(false)
{
- if(loadServants)
- {
- _value.resize(1024);
- }
_batchIterator = _batch.end();
}
@@ -74,14 +71,14 @@ Freeze::EvictorIteratorI::nextBatch()
return _batch.end();
}
- vector<EvictorI::EvictorElementPtr> evictorElements;
+ vector<EvictorElementPtr> evictorElements;
evictorElements.reserve(_batchSize);
Key firstKey;
firstKey = _key;
-
- int loadedGeneration = 0;
+ CommunicatorPtr communicator = _store->communicator();
+
try
{
for(;;)
@@ -93,15 +90,8 @@ Freeze::EvictorIteratorI::nextBatch()
initializeOutDbt(_key, dbKey);
Dbt dbValue;
- if(_loadServants)
- {
- initializeOutDbt(_value, dbValue);
- }
- else
- {
- dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
- }
-
+ dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
+
Dbc* dbc = 0;
try
{
@@ -109,7 +99,8 @@ Freeze::EvictorIteratorI::nextBatch()
// Move to the first record
//
u_int32_t flags = DB_NEXT;
- if(_key.size() > 0)
+
+ if(_initialized)
{
//
// _key represents the next element not yet returned
@@ -123,48 +114,47 @@ Freeze::EvictorIteratorI::nextBatch()
dbKey.set_size(static_cast<u_int32_t>(firstKey.size()));
}
- if(_loadServants)
- {
- loadedGeneration = _evictor.currentGeneration();
- }
+ _store->db()->cursor(0, &dbc, 0);
- _evictor.db()->cursor(0, &dbc, 0);
-
- for(;;)
+ bool done = false;
+ do
{
- try
+ for(;;)
{
- _more = (dbc->get(&dbKey, &dbValue, flags) == 0);
- if(_more)
+ try
{
- _key.resize(dbKey.get_size());
- //
- // No need to resize data as we never use it as input
- //
+ _more = (dbc->get(&dbKey, &dbValue, flags) == 0);
+ if(_more)
+ {
+ _key.resize(dbKey.get_size());
+ _initialized = true;
+
+ flags = DB_NEXT;
+
+ Ice::Identity ident;
+ ObjectStore::unmarshal(ident, _key, communicator);
+ if(_batch.size() < _batchSize)
+ {
+ _batch.push_back(ident);
+ }
+ else
+ {
+ //
+ // Keep the last element in _key
+ //
+ done = true;
+ }
+ }
+ break;
+ }
+ catch(const DbMemoryException& dx)
+ {
+ handleMemoryException(dx, _key, dbKey);
}
- break;
- }
- catch(const DbMemoryException& dx)
- {
- handleMemoryException(dx, _key, dbKey, _value, dbValue);
- }
- }
-
- while(_batch.size() < _batchSize && _more)
- {
- //
- // Even when count is 0, we read one more record (unless we reach the end)
- //
- if(_loadServants)
- {
- _more = _evictor.load(dbc, _key, _value, _batch, evictorElements);
- }
- else
- {
- _more = _evictor.load(dbc, _key, _batch);
}
}
-
+ while(!done && _more);
+
Dbc* toClose = dbc;
dbc = 0;
toClose->close();
@@ -222,10 +212,6 @@ Freeze::EvictorIteratorI::nextBatch()
}
else
{
- if(_loadServants)
- {
- _evictor.insert(_batch, evictorElements, loadedGeneration);
- }
return _batch.begin();
}
}