Merge pull request #24 from apache/add-reshard-ioq-priority

Add a proper reshard ioq class
diff --git a/include/ioq.hrl b/include/ioq.hrl
index 9e9bf67..7c4a4a4 100644
--- a/include/ioq.hrl
+++ b/include/ioq.hrl
@@ -44,7 +44,8 @@
     {other, 1.0},
     {interactive, 1.0},
     {system, 1.0},
-    {search, 1.0}
+    {search, 1.0},
+    {reshard, 0.001}
 ]).
 
 
@@ -72,6 +73,7 @@
     | system
     | search
     | internal_repl
+    | reshard
     | other
     | customer
     | db_meta
diff --git a/operator_guide.md b/operator_guide.md
index 81acdcc..43abee0 100644
--- a/operator_guide.md
+++ b/operator_guide.md
@@ -46,6 +46,8 @@
 | internal_repl | replication   | IO requests related to internal            |
 |               |               | replication.                               |
 |               |               |                                            |
+| reshard       | reshard       | IO requests related to resharding jobs     |
+|               |               |                                            |
 | low           | low           | IO requests related to requests made by    |
 |               |               | users via the http layer where the         |
 |               |               | "x-cloudant-priority: low" header is set.  |
diff --git a/priv/stats_descriptions.cfg b/priv/stats_descriptions.cfg
index 44bb128..a02931c 100644
--- a/priv/stats_descriptions.cfg
+++ b/priv/stats_descriptions.cfg
@@ -62,6 +62,10 @@
     {type, counter},
     {desc, <<"IO related to internal system activities">>}
 ]}.
+{[couchdb, io_queue, reshard], [
+    {type, counter},
+    {desc, <<"IO related to resharding jobs">>}
+]}.
 {[couchdb, io_queue, other], [
     {type, counter},
     {desc, <<"IO related to internal replication">>}
@@ -126,6 +130,10 @@
     {type, counter},
     {desc, <<"bypassed IO related to internal system activities">>}
 ]}.
+{[couchdb, io_queue_bypassed, reshard], [
+    {type, counter},
+    {desc, <<"bypassed IO related to resharding jobs">>}
+]}.
 {[couchdb, io_queue_bypassed, other], [
     {type, counter},
     {desc, <<"bypassed IO related to internal replication">>}
@@ -214,6 +222,10 @@
     {type, counter},
     {desc, <<"IO related to internal system activities">>}
 ]}.
+{[couchdb, io_queue2, reshard, count], [
+    {type, counter},
+    {desc, <<"IO related to resharding jobs">>}
+]}.
 {[couchdb, io_queue2, other, count], [
     {type, counter},
     {desc, <<"IO related to internal replication">>}
diff --git a/src/ioq_server.erl b/src/ioq_server.erl
index 78f16ca..b23dc10 100644
--- a/src/ioq_server.erl
+++ b/src/ioq_server.erl
@@ -228,6 +228,8 @@
     {view_compact, nil};
 analyze_priority({internal_repl, _Shard}) ->
     {internal_repl, nil};
+analyze_priority({reshard, _Shard}) ->
+    {reshard, nil};
 analyze_priority({system, _Shard}) ->
     {system, nil};
 analyze_priority({low, _Shard}) ->
@@ -257,6 +259,8 @@
     State#state{qC = update_queue(Req, State#state.qC, State#state.dedupe)};
 enqueue_request(#request{class = internal_repl} = Req, State) ->
     State#state{qR = update_queue(Req, State#state.qR, State#state.dedupe)};
+enqueue_request(#request{class = reshard} = Req, State) ->
+    State#state{qR = update_queue(Req, State#state.qR, State#state.dedupe)};
 enqueue_request(#request{class = low} = Req, State) ->
     State#state{qL = update_queue(Req, State#state.qL, State#state.dedupe)};
 enqueue_request(Req, State) ->
@@ -473,6 +477,8 @@
     <<"writes">>;
 make_key(system, _) ->
     <<"system">>;
+make_key(reshard, _) ->
+    <<"reshard">>;
 make_key(search, _) ->
     <<"search">>;
 make_key(_, _) ->
diff --git a/src/ioq_server2.erl b/src/ioq_server2.erl
index 85ffa2c..f7c3907 100644
--- a/src/ioq_server2.erl
+++ b/src/ioq_server2.erl
@@ -776,6 +776,7 @@
         #ioq_request{user=Foo, class=view_update},
         #ioq_request{user=Foo, class=view_update},
         #ioq_request{user=Foo, class=view_update},
+        #ioq_request{user=Foo, class=reshard},
 
         #ioq_request{user=Bar, class=interactive},
         #ioq_request{user=Bar, class=db_update},
@@ -788,7 +789,7 @@
         {replication, 3},
         {low, 1},
         {channels, {[
-            {<<"foo">>, [2,1,4]},
+            {<<"foo">>, [3,1,4]},
             {<<"bar">>, [1,3,1]}
         ]}}
     ],
@@ -1028,7 +1029,7 @@
 
 
 io_classes() -> [interactive, view_update, db_compact, view_compact,
-    internal_repl, other, db_meta].
+    internal_repl, other, db_meta, reshard].
 
 
 shards() ->
diff --git a/test/ioq_tests.erl b/test/ioq_tests.erl
index 51bc0d3..2e866a4 100644
--- a/test/ioq_tests.erl
+++ b/test/ioq_tests.erl
@@ -55,7 +55,7 @@
     ?_assertEqual({reply, Call}, ioq:call(Server, Call, Priority)).
 
 io_classes() -> [interactive, view_update, db_compact, view_compact,
-    internal_repl, other, search, system].
+    internal_repl, other, search, system, reshard].
 
 shards() ->
     [