FoundationDB/fdb-document-layer

Add renameCollection command

Closed this issue ยท 7 comments

apkar commented
> db.adminCommand( { renameCollection: "vishaltest.stores", to : "vishaltest.stores123"})

{

"errmsg" : "no such cmd: renamecollection",

"bad cmd" : "{ renameCollection: "vishaltest.stores", to: "vishaltest.stores123" }",

"ok" : 0

}

> use vishaltest

switched to db vishaltest

> db.stores.renameCollection("stores1234")

{

"errmsg" : "no such cmd: renamecollection",

"bad cmd" : "{ renameCollection: "vishaltest.stores", to: "vishaltest.stores1234", dropTarget: false }",

"ok" : 0

}

>

@apkar We like to take up this ticket. The proposed solution is,

  • Register new command for Rename
  • Validate the collection name for existence
  • Use MOVE function to create and update the directory path
  • Add internal_doDropIndexesActor function to update system.indexes

Please assign it to me, if this is ok.

apkar commented

@senthil-db-expert Why do you need to drop the indexes ?

apkar commented

If we take a simple case with a collection and index like below

db = client['test']
db.coll.create_index('field_a')
db.coll.insert_one({'field_a': 'value_a_1', '_id': 'Bhaskar'})

Assuming it creates directory structure like below

โ—
โ”œโ”€โ”€ Status Monitor -> \x15\x35
โ”‚   โ””โ”€โ”€ Layers -> \x15\x08
โ””โ”€โ”€ document -> \x15\x1c
    โ””โ”€โ”€ test -> \x15\x1d
        โ”œโ”€โ”€ coll -> \x15\x07
        โ”‚   โ””โ”€โ”€ metadata -> \x15\x2c
        โ””โ”€โ”€ system.indexes -> \x15\x16
            โ””โ”€โ”€ metadata -> \x15\x31

We will have primary index

`\x15\x07(Bhaskar\x00' is `2'
`\x15\x07(Bhaskar\x00(_id\x00' is `(Bhaskar'
`\x15\x07(Bhaskar\x00(field_a\x00' is `(value_a_1'

And secondary index

`\x15\x2c(indices\x00(field_a\x00(value_a_1\x00(Bhaskar\x00' is `'

We don't have to rewrite any of the primary/secondary index keys. We will need to rename (or move) the directory path and change the entry in system.indexes to point to new namespace. And it should bump the metadata version for the collection.

Agree @apkar Thanks. Will work on it and raise the PR.

@apkar the fix is ready. We will be raising PR today under account drkannan

@apkar any reason why this issue still in open state? Like to understand the process.

apkar commented

Usually, if a single PR is closing an issue, we go with the following keywords which would automatically close the issue.

https://help.github.com/en/articles/closing-issues-using-keywords

Also, it's just me being lazy.