Skip to content

Commit

Permalink
chedck for indexes on $inc updates. disallow the update then for now …
Browse files Browse the repository at this point in the history
…-- but will eventually allow and just update

the index
  • Loading branch information
dwight authored and dwight committed Aug 28, 2008
1 parent d434796 commit 5bd0db4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions db/jsobj.h
Expand Up @@ -223,6 +223,8 @@ class JSObj {
string toString() const;
/* note: addFields always adds _id even if not specified */
int addFields(JSObj& from, set<string>& fields); /* returns n added */

/* adds the field names to the fields set. does NOT clear it (appends). */
int getFieldNames(set<string>& fields);

/* return has eoo() true if no match
Expand Down
10 changes: 7 additions & 3 deletions db/namespace.cpp
@@ -1,4 +1,4 @@
//namespacedetails.cpp
// namespacedetails.cpp

/**
* Copyright (C) 2008 10gen Inc.
Expand Down Expand Up @@ -313,7 +313,11 @@ NamespaceDetailsTransient& NamespaceDetailsTransient::get(const char *ns) {

void NamespaceDetailsTransient::computeIndexKeys() {
NamespaceDetails *d = nsdetails(ns.c_str());
//FINISH
for( int i = 0; i < d->nIndexes; i++ ) {
// set<string> fields;
d->indexes[i].key().getFieldNames(allIndexKeys);
// allIndexKeys.insert(fields.begin(),fields.end());
}
}

/* ------------------------------------------------------------------------- */
Expand All @@ -323,7 +327,7 @@ void NamespaceDetailsTransient::computeIndexKeys() {
*/
void addNewNamespaceToCatalog(const char *ns, JSObj *options = 0) {
log() << "New namespace: " << ns << endl;
if( strstr(ns, "system.namespaces") ) {
if( strstr(ns, "system.namespaces``") ) {
// system.namespaces holds all the others, so it is not explicitly listed in the catalog.
// TODO: fix above should not be strstr!
return;
Expand Down
16 changes: 10 additions & 6 deletions db/namespace.h
Expand Up @@ -79,6 +79,13 @@ class IndexDetails {
*/
void getKeysFromObject(JSObj& obj, set<JSObj>& keys);

/* get the key pattern for this object.
e.g., { lastname:1, firstname:1 }
*/
JSObj key() {
return info.obj().getObjectField("key");
}

// returns name of this index's storage area
// client.table.$index
string indexNamespace() {
Expand Down Expand Up @@ -216,15 +223,12 @@ class NamespaceDetailsTransient : boost::noncopyable {
/* get set of index keys for this namespace. handy to quickly check if a given
field is indexed (Note it might be a seconary component of a compound index.)
*/

//TODO USE THIS IN $INC

set<string>& indexKeys() {
if( !haveIndexKeys ) { computeIndexKeys(); haveIndexKeys=true; }
set<string>& indexKeys() {
if( !haveIndexKeys ) { haveIndexKeys=true; computeIndexKeys(); }
return allIndexKeys;
}

void addedIndex() { haveIndexKeys=false; }
void addedIndex() { haveIndexKeys=false; }
private:
static map<const char *,NamespaceDetailsTransient*> map;
public:
Expand Down
8 changes: 8 additions & 0 deletions db/query.cpp
Expand Up @@ -358,6 +358,14 @@ int _updateObjects(const char *ns, JSObj updateobj, JSObj pattern, bool upsert,
if( firstField[0] == '$' ) {
vector<Mod> mods;
Mod::getMods(mods, updateobj);
NamespaceDetailsTransient& ndt = NamespaceDetailsTransient::get(ns);
set<string>& idxKeys = ndt.indexKeys();
for( vector<Mod>::iterator i = mods.begin(); i != mods.end(); i++ ) {
if( idxKeys.count(i->fieldName) ) {
assert(false);
}
}

Mod::applyMods(mods, c->currLoc().obj());
if( profile )
ss << " fastmod ";
Expand Down

0 comments on commit 5bd0db4

Please sign in to comment.