{"action":"created","comment":{"url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/comments/48996983","id":48996983,"diff_hunk":"@@ -0,0 +1,156 @@\n+# Meta\n+\n+ - RFC Name: Index Management\n+ - RFC ID: 0003-indexmanagement\n+ - Start Date: 2015-12-14\n+ - Owner: Simon Baslé (@simonbasle)\n+ - Current Status: Draft\n+\n+# Summary\n+The aim of the \"`Index Management`\" RFC is to offer a simplified API in the `BucketManager` to list, create and drop indexes, for the majority of use cases. In this sense, it is focused on GSI indexes and assumes a few other givens. For cases that don't fit in this picture, the fallback for the user is to craft appropriate `N1QL` queries (eg. in Java using the `Index` fluent API).\n+\n+# Motivation\n+The goal is to abstract away regularly needed queries relative to indexes and provide a simple API. This way the user can focus on his business related `N1QL` queries, without having to think twice about the boilerplate of creating indexes.\n+\n+# General Design\n+The API will be added to the `BucketManager` class of each SDK. In its blocking form, the API is made up of at least **6** base methods:\n+ - `listIndex`: lists all the indexes relating to the current `Bucket` using the `system:indexes` N1QL view.\n+ - `createPrimaryIndex`: create a primary index on the current Bucket.\n+ - `createIndex`: create a secondary GSI index on the current Bucket.\n+ - `dropPrimaryIndex`: drop the current Bucket's primary index.\n+ - `dropIndex`: drop a specific secondary index of the current Bucket.\n+ - `buildDeferredIndexes`: trigger the build of indexes that were created in a deferred fashion (see below).\n+\n+Additionally it is open for discussion wether or not this RFC should also include the following ***2*** methods in a cross-SDK fashion, or if they should be optional:\n+ - `watchIndex`: poll the `system:indexes` N1QL view until a given index changes its status to \"online\" (or a maximum amount of time has passed).\n+ - `watchIndexes`: poll the `system:indexes` N1QL view until a given list of index all become \"online\" (or a maximum amount of time has passed).\n+\n+\n+The underlying design would be to rely on existing `N1QL` verbs and, for the listing and polling part, to use the `system:indexes` keyspace. Each method will internally create and execute a specific N1QL query according to its parameter and the name of the current Bucket.\n+\n+Each method will offer a bit of tuning with a couple of parameters, so let's detail a more complete signature for each one.\n+\n+## Listing Indexes\n+Signature:\n+```java\n+List<IndexInfo> listIndexes()\n+```\n+\n+Remarks:\n+The method relies on `system:indexes` with the following N1QL statement:\n+```sql\n+SELECT idx.* FROM system:indexes AS idx WHERE keyspace_id = `BUCKET_NAME_INJECTED_HERE` ORDER BY is_primary DESC, name ASC;\n+```\n+\n+For SDK in language with no dynamic typing, each row will be converted to a `IndexInfo` object with the following attributes:\n+\n+```java\n+String name\n+boolean isPrimary\n+IndexType type //enum type GSI/VIEW\n+String rawType //raw string type in case a new index type is introduced, for forward-compatibility\n+String state //eg. \"online\", \"pending\"\n+String keyspace\n+String namespace\n+JsonArray indexKey //or equivalent Json representation\n+```\n+\n+## Creating Indexes\n+There are two specificities for index creation (both of primary and secondary indexes): the index could already exist and there is the possibility of deferring the build.\n+\n+In the first specificity, it makes sense to offer two alternatives: either this is considered an error (as N1QL does) or the creation should be purely and simply ignored.\n+This choice can be made through a first `boolean` parameter, `ignoreIfExist`. If it is `false`, then a SDK-related exception should be raised (eg. in Java a `CouchbaseException`).\n+\n+The second specificity can be triggered by another `boolean` parameter, `defer`. If set to true, the N1QL query will use the \"with defer\" syntax and the index will simply be \"pending\".\n+\n+Signatures:\n+```java\n+boolean createPrimaryIndex(boolean ignoreIfExist, boolean defer)\n+\n+boolean createIndex(String indexName, List<String> fields, boolean ignoreIfExist, boolean defer)\n+```","path":"rfc/0003-indexmanagement.md","position":71,"original_position":71,"commit_id":"4e75b65b58533c1fc89f5da0a6f90065ff87afa3","original_commit_id":"4e75b65b58533c1fc89f5da0a6f90065ff87afa3","user":{"login":"jeffrymorris","id":454176,"avatar_url":"https://avatars.githubusercontent.com/u/454176?v=3","gravatar_id":"","url":"https://api.github.com/users/jeffrymorris","html_url":"https://github.com/jeffrymorris","followers_url":"https://api.github.com/users/jeffrymorris/followers","following_url":"https://api.github.com/users/jeffrymorris/following{/other_user}","gists_url":"https://api.github.com/users/jeffrymorris/gists{/gist_id}","starred_url":"https://api.github.com/users/jeffrymorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeffrymorris/subscriptions","organizations_url":"https://api.github.com/users/jeffrymorris/orgs","repos_url":"https://api.github.com/users/jeffrymorris/repos","events_url":"https://api.github.com/users/jeffrymorris/events{/privacy}","received_events_url":"https://api.github.com/users/jeffrymorris/received_events","type":"User","site_admin":false},"body":"I think we need an overload here for complex indexes. For example, index hints:\r\n\r\n    CREATE INDEX `pv_ndx_02` ON `default`(`userId`,(meta().`id`),`type`) \r\n    WHERE ((`type` = 'pv') \r\n    AND ((to_number(`userId`) % 2) = 0)) USING GSI;\r\n\r\nUnless of course, if by \"fields\" you meant \"indexes\"...","created_at":"2016-01-06T19:20:19Z","updated_at":"2016-01-06T19:20:19Z","html_url":"https://github.com/couchbaselabs/sdk-rfcs/pull/7#discussion_r48996983","pull_request_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/comments/48996983"},"html":{"href":"https://github.com/couchbaselabs/sdk-rfcs/pull/7#discussion_r48996983"},"pull_request":{"href":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/7","id":53583377,"html_url":"https://github.com/couchbaselabs/sdk-rfcs/pull/7","diff_url":"https://github.com/couchbaselabs/sdk-rfcs/pull/7.diff","patch_url":"https://github.com/couchbaselabs/sdk-rfcs/pull/7.patch","issue_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues/7","number":7,"state":"open","locked":false,"title":"0003 Index Management RFC","user":{"login":"simonbasle","id":6986166,"avatar_url":"https://avatars.githubusercontent.com/u/6986166?v=3","gravatar_id":"","url":"https://api.github.com/users/simonbasle","html_url":"https://github.com/simonbasle","followers_url":"https://api.github.com/users/simonbasle/followers","following_url":"https://api.github.com/users/simonbasle/following{/other_user}","gists_url":"https://api.github.com/users/simonbasle/gists{/gist_id}","starred_url":"https://api.github.com/users/simonbasle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonbasle/subscriptions","organizations_url":"https://api.github.com/users/simonbasle/orgs","repos_url":"https://api.github.com/users/simonbasle/repos","events_url":"https://api.github.com/users/simonbasle/events{/privacy}","received_events_url":"https://api.github.com/users/simonbasle/received_events","type":"User","site_admin":false},"body":"@couchbaselabs/sdk-team please start reviewing and looking into SDK specifics.\r\n\r\nThe current prototype implementation is in Java, see http://review.couchbase.org/#/c/57530/\r\n\r\nSee associated issue #6","created_at":"2015-12-14T15:59:59Z","updated_at":"2016-01-06T19:20:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"188eb3a9cdf82e9d3a9a97cc0cef37cca8b425bc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/7/commits","review_comments_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/7/comments","review_comment_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues/7/comments","statuses_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/statuses/4e75b65b58533c1fc89f5da0a6f90065ff87afa3","head":{"label":"couchbaselabs:drafts/0003-indexmanagement","ref":"drafts/0003-indexmanagement","sha":"4e75b65b58533c1fc89f5da0a6f90065ff87afa3","user":{"login":"couchbaselabs","id":636956,"avatar_url":"https://avatars.githubusercontent.com/u/636956?v=3","gravatar_id":"","url":"https://api.github.com/users/couchbaselabs","html_url":"https://github.com/couchbaselabs","followers_url":"https://api.github.com/users/couchbaselabs/followers","following_url":"https://api.github.com/users/couchbaselabs/following{/other_user}","gists_url":"https://api.github.com/users/couchbaselabs/gists{/gist_id}","starred_url":"https://api.github.com/users/couchbaselabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/couchbaselabs/subscriptions","organizations_url":"https://api.github.com/users/couchbaselabs/orgs","repos_url":"https://api.github.com/users/couchbaselabs/repos","events_url":"https://api.github.com/users/couchbaselabs/events{/privacy}","received_events_url":"https://api.github.com/users/couchbaselabs/received_events","type":"Organization","site_admin":false},"repo":{"id":44797604,"name":"sdk-rfcs","full_name":"couchbaselabs/sdk-rfcs","owner":{"login":"couchbaselabs","id":636956,"avatar_url":"https://avatars.githubusercontent.com/u/636956?v=3","gravatar_id":"","url":"https://api.github.com/users/couchbaselabs","html_url":"https://github.com/couchbaselabs","followers_url":"https://api.github.com/users/couchbaselabs/followers","following_url":"https://api.github.com/users/couchbaselabs/following{/other_user}","gists_url":"https://api.github.com/users/couchbaselabs/gists{/gist_id}","starred_url":"https://api.github.com/users/couchbaselabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/couchbaselabs/subscriptions","organizations_url":"https://api.github.com/users/couchbaselabs/orgs","repos_url":"https://api.github.com/users/couchbaselabs/repos","events_url":"https://api.github.com/users/couchbaselabs/events{/privacy}","received_events_url":"https://api.github.com/users/couchbaselabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/couchbaselabs/sdk-rfcs","description":"SDK RFCs","fork":false,"url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs","forks_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/forks","keys_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/teams","hooks_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/hooks","issue_events_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/events","assignees_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/tags","blobs_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/languages","stargazers_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/stargazers","contributors_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/contributors","subscribers_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/subscribers","subscription_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/subscription","commits_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/merges","archive_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/downloads","issues_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/labels{/name}","releases_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/releases{/id}","created_at":"2015-10-23T07:26:18Z","updated_at":"2015-10-23T07:26:18Z","pushed_at":"2016-01-05T17:54:50Z","git_url":"git://github.com/couchbaselabs/sdk-rfcs.git","ssh_url":"git@github.com:couchbaselabs/sdk-rfcs.git","clone_url":"https://github.com/couchbaselabs/sdk-rfcs.git","svn_url":"https://github.com/couchbaselabs/sdk-rfcs","homepage":null,"size":18,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":0,"default_branch":"master"}},"base":{"label":"couchbaselabs:master","ref":"master","sha":"1f52b573de725142f3a1e3dcff27ed25abdaa191","user":{"login":"couchbaselabs","id":636956,"avatar_url":"https://avatars.githubusercontent.com/u/636956?v=3","gravatar_id":"","url":"https://api.github.com/users/couchbaselabs","html_url":"https://github.com/couchbaselabs","followers_url":"https://api.github.com/users/couchbaselabs/followers","following_url":"https://api.github.com/users/couchbaselabs/following{/other_user}","gists_url":"https://api.github.com/users/couchbaselabs/gists{/gist_id}","starred_url":"https://api.github.com/users/couchbaselabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/couchbaselabs/subscriptions","organizations_url":"https://api.github.com/users/couchbaselabs/orgs","repos_url":"https://api.github.com/users/couchbaselabs/repos","events_url":"https://api.github.com/users/couchbaselabs/events{/privacy}","received_events_url":"https://api.github.com/users/couchbaselabs/received_events","type":"Organization","site_admin":false},"repo":{"id":44797604,"name":"sdk-rfcs","full_name":"couchbaselabs/sdk-rfcs","owner":{"login":"couchbaselabs","id":636956,"avatar_url":"https://avatars.githubusercontent.com/u/636956?v=3","gravatar_id":"","url":"https://api.github.com/users/couchbaselabs","html_url":"https://github.com/couchbaselabs","followers_url":"https://api.github.com/users/couchbaselabs/followers","following_url":"https://api.github.com/users/couchbaselabs/following{/other_user}","gists_url":"https://api.github.com/users/couchbaselabs/gists{/gist_id}","starred_url":"https://api.github.com/users/couchbaselabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/couchbaselabs/subscriptions","organizations_url":"https://api.github.com/users/couchbaselabs/orgs","repos_url":"https://api.github.com/users/couchbaselabs/repos","events_url":"https://api.github.com/users/couchbaselabs/events{/privacy}","received_events_url":"https://api.github.com/users/couchbaselabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/couchbaselabs/sdk-rfcs","description":"SDK RFCs","fork":false,"url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs","forks_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/forks","keys_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/teams","hooks_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/hooks","issue_events_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/events","assignees_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/tags","blobs_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/languages","stargazers_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/stargazers","contributors_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/contributors","subscribers_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/subscribers","subscription_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/subscription","commits_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/merges","archive_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/downloads","issues_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/labels{/name}","releases_url":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/releases{/id}","created_at":"2015-10-23T07:26:18Z","updated_at":"2015-10-23T07:26:18Z","pushed_at":"2016-01-05T17:54:50Z","git_url":"git://github.com/couchbaselabs/sdk-rfcs.git","ssh_url":"git@github.com:couchbaselabs/sdk-rfcs.git","clone_url":"https://github.com/couchbaselabs/sdk-rfcs.git","svn_url":"https://github.com/couchbaselabs/sdk-rfcs","homepage":null,"size":18,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/7"},"html":{"href":"https://github.com/couchbaselabs/sdk-rfcs/pull/7"},"issue":{"href":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues/7"},"comments":{"href":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/couchbaselabs/sdk-rfcs/statuses/4e75b65b58533c1fc89f5da0a6f90065ff87afa3"}}}}