aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-04-19 15:37:56 +0000
committerMike Buland <eichlan@xagasoft.com>2010-04-19 15:37:56 +0000
commitd8a8c482b2f6b09ee8995b9563397a9b9bd135e8 (patch)
treed0fd5a6aa809f9caa67ff4723a04cff84e42615c
parent668737effd601778fba74edec14d22dd5b87457a (diff)
downloadlibbu++-d8a8c482b2f6b09ee8995b9563397a9b9bd135e8.tar.gz
libbu++-d8a8c482b2f6b09ee8995b9563397a9b9bd135e8.tar.bz2
libbu++-d8a8c482b2f6b09ee8995b9563397a9b9bd135e8.tar.xz
libbu++-d8a8c482b2f6b09ee8995b9563397a9b9bd135e8.zip
Nevermind about the Myriad bug. It was really obvious, I was accidentally
adding all pre-allocated blocks to the header stream instead of just allocating them. This caused some oddness, as you can probably imagine. There's a good way to go before Myriad is as cool as it could be, but it's already much more efficient and all around better than nids. I'll have to write a program to convert nids cache stores to myriad cache stores, but that should be fairly minor.
-rw-r--r--src/cachestoremyriad.h3
-rw-r--r--src/myriad.cpp63
-rw-r--r--src/myriad.h1
3 files changed, 37 insertions, 30 deletions
diff --git a/src/cachestoremyriad.h b/src/cachestoremyriad.h
index a40ffb2..e5a10eb 100644
--- a/src/cachestoremyriad.h
+++ b/src/cachestoremyriad.h
@@ -16,8 +16,6 @@
16 16
17#include "bu/archive.h" 17#include "bu/archive.h"
18 18
19#include "bu/sio.h"
20
21namespace Bu 19namespace Bu
22{ 20{
23 template<class keytype, class obtype> 21 template<class keytype, class obtype>
@@ -60,7 +58,6 @@ namespace Bu
60 MyriadStream ns = mStore.openStream( 1 ); 58 MyriadStream ns = mStore.openStream( 1 );
61 Bu::Archive ar( ns, Bu::Archive::load ); 59 Bu::Archive ar( ns, Bu::Archive::load );
62 ar >> hId; 60 ar >> hId;
63 Bu::sio << hId << Bu::sio.nl;
64 } 61 }
65 catch( Bu::MyriadException &e ) 62 catch( Bu::MyriadException &e )
66 { 63 {
diff --git a/src/myriad.cpp b/src/myriad.cpp
index 77b481d..a95e885 100644
--- a/src/myriad.cpp
+++ b/src/myriad.cpp
@@ -28,7 +28,8 @@ Bu::Myriad::Myriad( Bu::Stream &sStore ) :
28 sStore( sStore ), 28 sStore( sStore ),
29 iBlockSize( 0 ), 29 iBlockSize( 0 ),
30 iBlocks( 0 ), 30 iBlocks( 0 ),
31 iUsed( 0 ) 31 iUsed( 0 ),
32 bHeaderChanged( false )
32{ 33{
33} 34}
34 35
@@ -86,8 +87,8 @@ void Bu::Myriad::initialize()
86 sStore.read( &iStreams, 4 ); 87 sStore.read( &iStreams, 4 );
87 88
88 iBlocks = iSize/iBlockSize; 89 iBlocks = iSize/iBlockSize;
89 sio << "Myriad: iSize=" << iSize << ", iBlockSize=" << iBlockSize 90 //sio << "Myriad: iSize=" << iSize << ", iBlockSize=" << iBlockSize
90 << ", iBlocks=" << iBlocks << ", iStreams=" << iStreams << sio.nl; 91 // << ", iBlocks=" << iBlocks << ", iStreams=" << iStreams << sio.nl;
91 92
92 int iHeaderSize = 14 + 8 + 4; 93 int iHeaderSize = 14 + 8 + 4;
93 int iHeaderBlocks = 0; //blkDiv( iHeaderSize+4, iBlockSize ); 94 int iHeaderBlocks = 0; //blkDiv( iHeaderSize+4, iBlockSize );
@@ -98,8 +99,8 @@ void Bu::Myriad::initialize()
98 iHeaderSize = 14 + 8 + 4*iHeaderBlocks; 99 iHeaderSize = 14 + 8 + 4*iHeaderBlocks;
99 } 100 }
100 101
101 sio << "Myriad: iHeaderSize=" << iHeaderSize 102 //sio << "Myriad: iHeaderSize=" << iHeaderSize
102 << ", iHeaderBlocks=" << iHeaderBlocks << sio.nl; 103 // << ", iHeaderBlocks=" << iHeaderBlocks << sio.nl;
103 104
104 Stream *pFakeHdr = new Stream; 105 Stream *pFakeHdr = new Stream;
105 pFakeHdr->iId = 0; 106 pFakeHdr->iId = 0;
@@ -121,26 +122,26 @@ void Bu::Myriad::initialize()
121 pIn->read( &s.iId, 4 ); 122 pIn->read( &s.iId, 4 );
122 pIn->read( &s.iSize, 4 ); 123 pIn->read( &s.iSize, 4 );
123 int iSBlocks = blkDiv(s.iSize, iBlockSize); 124 int iSBlocks = blkDiv(s.iSize, iBlockSize);
124 sio << "Myriad: - Stream::iId=" << s.iId 125 // sio << "Myriad: - Stream::iId=" << s.iId
125 << ", Stream::iSize=" << s.iSize 126 // << ", Stream::iSize=" << s.iSize
126 << ", Stream::aBlocks=" << iSBlocks 127 // << ", Stream::aBlocks=" << iSBlocks
127 << ", pIn->tell()=" << pIn->tell() << sio.nl; 128 // << ", pIn->tell()=" << pIn->tell() << sio.nl;
128 for( int k = 0; k < iSBlocks; k++ ) 129 for( int k = 0; k < iSBlocks; k++ )
129 { 130 {
130 int iBId; 131 int iBId;
131 pIn->read( &iBId, 4 ); 132 pIn->read( &iBId, 4 );
132 sio << "Myriad: - iBId=" << iBId 133 // sio << "Myriad: - iBId=" << iBId
133 << ", iStartPos=" << iBId*iBlockSize 134 // << ", iStartPos=" << iBId*iBlockSize
134 << ", pIn->tell()=" << pIn->tell() << sio.nl; 135 // << ", pIn->tell()=" << pIn->tell() << sio.nl;
135 s.aBlocks.append( iBId ); 136 s.aBlocks.append( iBId );
136 bsBlockUsed.setBit( iBId ); 137 bsBlockUsed.setBit( iBId );
137 if( (j == 0 && k == iHeaderBlocks-1) ) 138 if( (j == 0 && k == iHeaderBlocks-1) )
138 { 139 {
139 sio << "Myriad: - End of prepartition, unlocking skipping." 140 // sio << "Myriad: - End of prepartition, unlocking skipping."
140 << sio.nl; 141 // << sio.nl;
141 bCanSkip = true; 142 bCanSkip = true;
142 MyriadStream *pTmp = new MyriadStream( *this, aStreams[0] ); 143 MyriadStream *pTmp = new MyriadStream( *this, aStreams[0] );
143 sio << "Myriad - Position = " << pIn->tell() << sio.nl; 144 // sio << "Myriad - Position = " << pIn->tell() << sio.nl;
144 pTmp->setPos( pIn->tell() ); 145 pTmp->setPos( pIn->tell() );
145 delete pIn; 146 delete pIn;
146 delete pFakeHdr; 147 delete pFakeHdr;
@@ -150,7 +151,7 @@ void Bu::Myriad::initialize()
150 } 151 }
151 delete pIn; 152 delete pIn;
152 153
153 sio << "Myriad: Blocks used: " << bsBlockUsed.toString() << sio.nl; 154 //sio << "Myriad: Blocks used: " << bsBlockUsed.toString() << sio.nl;
154} 155}
155 156
156void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate ) 157void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate )
@@ -171,8 +172,8 @@ void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate )
171 172
172 iPreAllocate += iHeaderBlocks; 173 iPreAllocate += iHeaderBlocks;
173 174
174 sio << "Myriad: iHeaderSize=" << iHeaderSize << ", iBlockSize=" 175 //sio << "Myriad: iHeaderSize=" << iHeaderSize << ", iBlockSize="
175 << iBlockSize << ", iHeaderBlocks=" << iHeaderBlocks << sio.nl; 176 // << iBlockSize << ", iHeaderBlocks=" << iHeaderBlocks << sio.nl;
176 177
177 bsBlockUsed.setSize( iPreAllocate, true ); 178 bsBlockUsed.setSize( iPreAllocate, true );
178 179
@@ -181,7 +182,6 @@ void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate )
181 for( int j = 0; j < iPreAllocate; j++ ) 182 for( int j = 0; j < iPreAllocate; j++ )
182 { 183 {
183 sStore.write( pBlock, iBlockSize ); 184 sStore.write( pBlock, iBlockSize );
184 pStr->aBlocks.append( j );
185 } 185 }
186 delete[] (char *)pBlock; 186 delete[] (char *)pBlock;
187 187
@@ -228,23 +228,26 @@ void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate )
228 228
229 aStreams.append( pStr ); 229 aStreams.append( pStr );
230 230
231 sio << bsBlockUsed.toString() << sio.nl; 231 //sio << bsBlockUsed.toString() << " - " << pStr->aBlocks << sio.nl;
232 232
233 bHeaderChanged = true;
233 //hStreams.insert( 0, BlockArray( 0 ) ); 234 //hStreams.insert( 0, BlockArray( 0 ) );
234} 235}
235 236
236void Bu::Myriad::updateHeader() 237void Bu::Myriad::updateHeader()
237{ 238{
239 if( bHeaderChanged == false )
240 return;
238 if( !sStore.canWrite() ) 241 if( !sStore.canWrite() )
239 return; 242 return;
240 243
241 char cBuf; 244 char cBuf;
242 int iBuf; 245 int iBuf;
243 246
244 for( StreamArray::iterator i = aStreams.begin(); i; i++ ) 247 //for( StreamArray::iterator i = aStreams.begin(); i; i++ )
245 { 248 //{
246 sio << "Myriad: Stream " << Fmt(4) << (*i)->iId << ": " << (*i)->aBlocks << sio.nl; 249 // sio << "Myriad: Stream " << Fmt(4) << (*i)->iId << ": " << (*i)->aBlocks << sio.nl;
247 } 250 //}
248 251
249 // Compute the new size of the header. 252 // Compute the new size of the header.
250 int iHeaderSize = 14 + 8*aStreams.getSize(); 253 int iHeaderSize = 14 + 8*aStreams.getSize();
@@ -301,14 +304,16 @@ void Bu::Myriad::updateHeader()
301 sHdr.write( &(*i)->aBlocks[j], 4 ); 304 sHdr.write( &(*i)->aBlocks[j], 4 );
302 } 305 }
303 } 306 }
307
308 bHeaderChanged = false;
304} 309}
305 310
306int Bu::Myriad::createStream( int iPreAllocate ) 311int Bu::Myriad::createStream( int iPreAllocate )
307{ 312{
308 Stream *pStr = new Stream(); 313 Stream *pStr = new Stream();
309 pStr->iId = aStreams.last()->iId+1; 314 pStr->iId = aStreams.last()->iId+1;
310 sio << "Myriad: New stream id=" << pStr->iId << ", iPreAllocate=" 315 //sio << "Myriad: New stream id=" << pStr->iId << ", iPreAllocate="
311 << iPreAllocate << sio.nl; 316 // << iPreAllocate << sio.nl;
312 pStr->iSize = 0; 317 pStr->iSize = 0;
313 aStreams.append( pStr ); 318 aStreams.append( pStr );
314 319
@@ -320,11 +325,15 @@ int Bu::Myriad::createStream( int iPreAllocate )
320 bsBlockUsed.setBit( iFreeBlock ); 325 bsBlockUsed.setBit( iFreeBlock );
321 } 326 }
322 327
328 bHeaderChanged = true;
329
323 return pStr->iId; 330 return pStr->iId;
324} 331}
325 332
326int Bu::Myriad::findEmptyBlock() 333int Bu::Myriad::findEmptyBlock()
327{ 334{
335 bHeaderChanged = true;
336
328 for( int j = 0; j < bsBlockUsed.getSize(); j++ ) 337 for( int j = 0; j < bsBlockUsed.getSize(); j++ )
329 { 338 {
330 if( bsBlockUsed.getBit( j ) == false ) 339 if( bsBlockUsed.getBit( j ) == false )
@@ -349,7 +358,7 @@ void Bu::Myriad::deleteStream( int /*iID*/ )
349 358
350Bu::MyriadStream Bu::Myriad::openStream( int iId ) 359Bu::MyriadStream Bu::Myriad::openStream( int iId )
351{ 360{
352 sio << "Myriad: Request to open stream: " << iId << sio.nl; 361 //sio << "Myriad: Request to open stream: " << iId << sio.nl;
353 return MyriadStream( *this, findStream( iId ) ); 362 return MyriadStream( *this, findStream( iId ) );
354} 363}
355 364
diff --git a/src/myriad.h b/src/myriad.h
index 8f626a4..9bbc812 100644
--- a/src/myriad.h
+++ b/src/myriad.h
@@ -159,6 +159,7 @@ namespace Bu
159 StreamArray aStreams; 159 StreamArray aStreams;
160 typedef Bu::Hash<int, Block *> BlockHash; 160 typedef Bu::Hash<int, Block *> BlockHash;
161 BlockHash hActiveBlocks; 161 BlockHash hActiveBlocks;
162 bool bHeaderChanged;
162 }; 163 };
163}; 164};
164 165