mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
index updates
This commit is contained in:
parent
5d77507008
commit
2f735ca816
@ -307,7 +307,7 @@ int BtreeBucket::_insert(const DiskLoc& thisLoc, const char *ns, const DiskLoc&
|
||||
bool found = find(key, pos);
|
||||
if( found ) {
|
||||
// todo: support dup keys
|
||||
cout << "dup key failing" << endl;
|
||||
cout << " dup key failing" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -354,7 +354,7 @@ void DataFileMgr::update(
|
||||
Record *toupdate, const DiskLoc& dl,
|
||||
const char *buf, int len)
|
||||
{
|
||||
if( toupdate->netLength() < len ) {
|
||||
if( toupdate->netLength() < len ) {
|
||||
cout << "temp: update: moving record to a larger location " << ns << endl;
|
||||
// doesn't fit.
|
||||
deleteRecord(ns, toupdate, dl);
|
||||
@ -362,6 +362,35 @@ void DataFileMgr::update(
|
||||
return;
|
||||
}
|
||||
|
||||
/* has any index keys changed? */
|
||||
{
|
||||
NamespaceDetails *d = namespaceIndex.details(ns);
|
||||
if( d->nIndexes ) {
|
||||
JSObj newObj(buf);
|
||||
JSObj oldObj = dl.obj();
|
||||
for( int i = 0; i < d->nIndexes; i++ ) {
|
||||
IndexDetails& idx = d->indexes[i];
|
||||
JSObj idxKey = idx.info.obj().getObjectField("key");
|
||||
JSObjBuilder b1,b2;
|
||||
JSObj kNew = newObj.extractFields(idxKey, b1);
|
||||
JSObj kOld = oldObj.extractFields(idxKey, b2);
|
||||
if( !kNew.woEqual(kOld) ) {
|
||||
cout << " updating index, key changed " << idx.indexNamespace() << endl;
|
||||
// delete old key
|
||||
if( !kOld.isEmpty() )
|
||||
idx.head.btree()->unindex(kOld);
|
||||
// add new key
|
||||
if( !kNew.isEmpty() ) {
|
||||
idx.head.btree()->insert(
|
||||
idx.head,
|
||||
idx.indexNamespace().c_str(),
|
||||
dl, kNew, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(toupdate->data, buf, len);
|
||||
}
|
||||
|
||||
|
30
db/query.cpp
30
db/query.cpp
@ -94,18 +94,26 @@ void updateObjects(const char *ns, JSObj updateobj, JSObj pattern, bool upsert)
|
||||
return;
|
||||
}
|
||||
|
||||
JSMatcher matcher(pattern);
|
||||
|
||||
auto_ptr<Cursor> c = theDataFileMgr.findAll(ns);
|
||||
while( c->ok() ) {
|
||||
Record *r = c->_current();
|
||||
JSObj js(r);
|
||||
if( matcher.matches(js) ) {
|
||||
cout << " found match to update" << endl;
|
||||
theDataFileMgr.update(ns, r, c->currLoc(), updateobj.objdata(), updateobj.objsize());
|
||||
return;
|
||||
{
|
||||
JSMatcher matcher(pattern);
|
||||
JSObj order;
|
||||
auto_ptr<Cursor> c = getIndexCursor(ns, pattern, order);
|
||||
if( c.get() == 0 )
|
||||
c = theDataFileMgr.findAll(ns);
|
||||
while( c->ok() ) {
|
||||
Record *r = c->_current();
|
||||
JSObj js(r);
|
||||
if( !matcher.matches(js) ) {
|
||||
if( c->tempStopOnMiss() )
|
||||
break;
|
||||
}
|
||||
else {
|
||||
cout << " found match to update" << endl;
|
||||
theDataFileMgr.update(ns, r, c->currLoc(), updateobj.objdata(), updateobj.objsize());
|
||||
return;
|
||||
}
|
||||
c->advance();
|
||||
}
|
||||
c->advance();
|
||||
}
|
||||
|
||||
cout << " no match found. ";
|
||||
|
Loading…
Reference in New Issue
Block a user