mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
cap by size
This commit is contained in:
parent
45b79abf1f
commit
00008aa0d6
@ -276,7 +276,7 @@ public:
|
||||
};
|
||||
|
||||
void listen(int port) {
|
||||
cout << "db version: 08mar2008 capped collections" << endl;
|
||||
cout << "db version: 08mar2008 capped collections.2" << endl;
|
||||
pdfileInit();
|
||||
testTheDb();
|
||||
cout << curTimeMillis() % 10000 << " waiting for connections...\n" << endl;
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
lastExtentSize = 0;
|
||||
nIndexes = 0;
|
||||
capped = 0;
|
||||
reservedddd = 0;
|
||||
max = 0x7fffffff;
|
||||
memset(reserved, 0, sizeof(reserved));
|
||||
}
|
||||
DiskLoc firstExtent;
|
||||
@ -89,7 +89,7 @@ public:
|
||||
int nIndexes;
|
||||
IndexDetails indexes[MaxIndexes];
|
||||
int capped;
|
||||
int reservedddd;
|
||||
int max; // max # of objects for a capped table.
|
||||
char reserved[256-16-4-4-8*MaxIndexes-8-8];
|
||||
|
||||
//returns offset in indexes[]
|
||||
|
@ -167,7 +167,7 @@ DiskLoc NamespaceDetails::__alloc(int len) {
|
||||
(or 3...there will be a little unused sliver at the end of the extent.)
|
||||
*/
|
||||
void NamespaceDetails::compact() {
|
||||
assert(capped==1);
|
||||
assert(capped);
|
||||
list<DiskLoc> drecs;
|
||||
|
||||
for( int i = 0; i < Buckets; i++ ) {
|
||||
@ -214,10 +214,14 @@ DiskLoc NamespaceDetails::_alloc(const char *ns, int len) {
|
||||
assert( len < 400000000 );
|
||||
int passes = 0;
|
||||
DiskLoc loc;
|
||||
|
||||
// delete records until we have room and the max # objects limit achieved.
|
||||
while( 1 ) {
|
||||
loc = __alloc(len);
|
||||
if( !loc.isNull() )
|
||||
break;
|
||||
if( nrecords < max ) {
|
||||
loc = __alloc(len);
|
||||
if( !loc.isNull() )
|
||||
break;
|
||||
}
|
||||
|
||||
DiskLoc fr = firstExtent.ext()->firstRecord;
|
||||
if( fr.isNull() ) {
|
||||
@ -299,11 +303,13 @@ int initialExtentSize(int len) {
|
||||
return z;
|
||||
}
|
||||
|
||||
// { ..., capped: true, size: ... }
|
||||
// { ..., capped: true, size: ..., max: ... }
|
||||
bool userCreateNS(const char *ns, JSObj& j) {
|
||||
if( nsdetails(ns) )
|
||||
return false;
|
||||
|
||||
cout << j.toString() << endl;
|
||||
|
||||
newNamespace(ns);
|
||||
|
||||
int ies = initialExtentSize(128);
|
||||
@ -320,8 +326,15 @@ bool userCreateNS(const char *ns, JSObj& j) {
|
||||
assert(d);
|
||||
|
||||
e = j.findElement("capped");
|
||||
if( e.type() == Bool && e.boolean() )
|
||||
if( e.type() == Bool && e.boolean() ) {
|
||||
d->capped = 1;
|
||||
e = j.findElement("max");
|
||||
if( e.type() == Number ) {
|
||||
int mx = (int) e.number();
|
||||
if( mx > 0 )
|
||||
d->max = mx;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
11
db/query.cpp
11
db/query.cpp
@ -300,17 +300,16 @@ int otherTraceLevel = 0;
|
||||
int initialExtentSize(int len);
|
||||
|
||||
void clean(const char *ns, NamespaceDetails *d) {
|
||||
// d->firstExtent.Null();
|
||||
// d->lastExtent.Null();
|
||||
for( int i = 0; i < Buckets; i++ )
|
||||
d->deletedList[i].Null();
|
||||
// d->datasize = 0; d->nrecords = 0; d->lastExtentSize = 0; d->nIndexes = 0;
|
||||
// client->newestFile()->newExtent(ns, initialExtentSize(500));
|
||||
}
|
||||
|
||||
string validateNS(const char *ns, NamespaceDetails *d) {
|
||||
stringstream ss;
|
||||
ss << "validate...\n";
|
||||
ss << "\nvalidate ";
|
||||
if( d->capped )
|
||||
cout << " capped:" << d->capped << " max:" << d->max;
|
||||
ss << "\n";
|
||||
|
||||
try {
|
||||
|
||||
@ -325,7 +324,7 @@ string validateNS(const char *ns, NamespaceDetails *d) {
|
||||
nlen += r->netLength();
|
||||
c->advance();
|
||||
}
|
||||
ss << " " << n << " objects found\n";
|
||||
ss << " " << n << " objects found, nobj:" << d->nrecords << "\n";
|
||||
ss << " " << len << " bytes record data w/headers\n";
|
||||
ss << " " << nlen << " bytes record data wout/headers\n";
|
||||
|
||||
|
@ -106,16 +106,21 @@ function testarrayindexing() {
|
||||
}
|
||||
}
|
||||
|
||||
function testcapped() {
|
||||
function testcapped(max) {
|
||||
print("testcapped");
|
||||
drop("capped");
|
||||
|
||||
assert( createCollection("capped", { size: 4096, capped:true } ).ok );
|
||||
assert( createCollection("capped", { size: 4096, capped:true, max:max } ).ok );
|
||||
|
||||
capped = db.capped;
|
||||
for(i=0; i<500; i++ ) {
|
||||
capped.save( { i: i, b: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyy" } );
|
||||
}
|
||||
|
||||
var a = capped.find().toArray();
|
||||
assert( a.length < 100 );
|
||||
assert( a[a.length-1].i == 499 );
|
||||
print("testcapped end");
|
||||
}
|
||||
|
||||
function testgetmore() {
|
||||
|
Loading…
Reference in New Issue
Block a user