<commit_before>%% @author Couchbase <<EMAIL>>
%% @copyright 2014 Couchbase, Inc.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%      http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% @doc api that contains almost everything that ns_server node calls on
%%      ns_couchdb node
%%

-module(ns_couchdb_api).

-include("ns_common.hrl").
-include("couch_db.hrl").

-export([set_db_and_ix_paths/2,
         get_db_and_ix_paths/0,
         get_tasks/0,
         get_tasks/2,
         restart_capi_ssl_service/0,
         fetch_stats/0,
         fetch_couch_stats/1,
         delete_databases_and_files/1,
         wait_index_updated/2,
         initiate_indexing/1,
         set_vbucket_states/3,
         reset_master_vbucket/1,
         get_design_doc_signatures/1,
         foreach_doc/3,
         update_doc/2,
         get_doc/2,

         get_master_vbucket_size/1,
         start_master_vbucket_compact/1,
         cancel_master_vbucket_compact/1,
         start_view_compact/5,
         cancel_view_compact/4,
         try_to_cleanup_indexes/1,
         get_view_group_data_size/3,
         get_safe_purge_seqs/1]).

-export([handle_rpc/1]).

-export([wait_for_doc_manager/0, register_doc_manager/1]).

-spec get_db_and_ix_paths() -> [{db_path | index_path, string()}].
get_db_and_ix_paths() ->
    maybe_rpc_couchdb_node(get_db_and_ix_paths).

-spec set_db_and_ix_paths(DbPath :: string(), IxPath :: string()) -> ok.
set_db_and_ix_paths(DbPath0, IxPath0) ->
    maybe_rpc_couchdb_node({set_db_and_ix_paths, DbPath0, IxPath0}).

-spec get_tasks() -> [{atom(), any()}].
get_tasks() ->
    maybe_rpc_couchdb_node(get_tasks).

-spec get_tasks(timeout(), [{atom(), any()}]) -> [{atom(), any()}].
get_tasks(RpcTimeout, Default) ->
    maybe_rpc_couchdb_node(get_tasks, RpcTimeout, Default).

restart_capi_ssl_service() ->
    maybe_rpc_couchdb_node(restart_capi_ssl_service).

fetch_stats() ->
    maybe_rpc_couchdb_node(fetch_stats).

fetch_couch_stats(BucketName) ->
    maybe_rpc_couchdb_node({fetch_couch_stats, BucketName}).

delete_databases_and_files(Bucket) ->
    case maybe_rpc_couchdb_node({delete_databases_and_files, Bucket}) of
        {delete_vbuckets_error, Error} ->
            ale:error(?USER_LOGGER, "Unable to delete some DBs for bucket ~s. Leaving bucket directory undeleted~n~p", [Bucket, Error]),
            Error;
        {rm_rf_error, Error} ->
            ale:error(?USER_LOGGER, "Unable to rm -rf bucket database directory ~s~n~p", [Bucket, Error]),
            Error;<commit_msg>MB-16209: Fix error message when deleting DB dir failed<commit_after>%% @author Couchbase <<EMAIL>>
%% @copyright 2014 Couchbase, Inc.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%      http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% @doc api that contains almost everything that ns_server node calls on
%%      ns_couchdb node
%%

-module(ns_couchdb_api).

-include("ns_common.hrl").
-include("couch_db.hrl").

-export([set_db_and_ix_paths/2,
         get_db_and_ix_paths/0,
         get_tasks/0,
         get_tasks/2,
         restart_capi_ssl_service/0,
         fetch_stats/0,
         fetch_couch_stats/1,
         delete_databases_and_files/1,
         wait_index_updated/2,
         initiate_indexing/1,
         set_vbucket_states/3,
         reset_master_vbucket/1,
         get_design_doc_signatures/1,
         foreach_doc/3,
         update_doc/2,
         get_doc/2,

         get_master_vbucket_size/1,
         start_master_vbucket_compact/1,
         cancel_master_vbucket_compact/1,
         start_view_compact/5,
         cancel_view_compact/4,
         try_to_cleanup_indexes/1,
         get_view_group_data_size/3,
         get_safe_purge_seqs/1]).

-export([handle_rpc/1]).

-export([wait_for_doc_manager/0, register_doc_manager/1]).

-spec get_db_and_ix_paths() -> [{db_path | index_path, string()}].
get_db_and_ix_paths() ->
    maybe_rpc_couchdb_node(get_db_and_ix_paths).

-spec set_db_and_ix_paths(DbPath :: string(), IxPath :: string()) -> ok.
set_db_and_ix_paths(DbPath0, IxPath0) ->
    maybe_rpc_couchdb_node({set_db_and_ix_paths, DbPath0, IxPath0}).

-spec get_tasks() -> [{atom(), any()}].
get_tasks() ->
    maybe_rpc_couchdb_node(get_tasks).

-spec get_tasks(timeout(), [{atom(), any()}]) -> [{atom(), any()}].
get_tasks(RpcTimeout, Default) ->
    maybe_rpc_couchdb_node(get_tasks, RpcTimeout, Default).

restart_capi_ssl_service() ->
    maybe_rpc_couchdb_node(restart_capi_ssl_service).

fetch_stats() ->
    maybe_rpc_couchdb_node(fetch_stats).

fetch_couch_stats(BucketName) ->
    maybe_rpc_couchdb_node({fetch_couch_stats, BucketName}).

delete_databases_and_files(Bucket) ->
    case maybe_rpc_couchdb_node({delete_databases_and_files, Bucket}) of
        {delete_vbuckets_error, Error} ->
            ale:error(?USER_LOGGER, "Unable to delete some DBs for bucket ~s. Leaving bucket directory undeleted~n~p", [Bucket, Error]),
            Error;
        {rm_rf_error, Error} ->
            ale:error(?USER_LOGGER, "Unable to delete bucket database directory ~s~n~p", [Bucket, Error]),
            Error;
{'fraction_non_alphanumeric': 0.11488294314381271, 'fraction_numerical': 0.013879598662207358, 'mean_word_length': 3.551750380517504, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5699833', 'n_tokens_mistral': 2053, 'n_tokens_neox': 2033, 'n_words': 422}