| 1887 | } |
| 1888 | |
| 1889 | static |
| 1890 | fdb_status _fdb_kvs_remove(fdb_file_handle *fhandle, |
| 1891 | const char *kvs_name, |
| 1892 | bool rollback_recreate) |
| 1893 | { |
| 1894 | size_t size_chunk, size_id; |
| 1895 | uint8_t *_kv_id; |
| 1896 | fdb_status fs = FDB_RESULT_SUCCESS; |
| 1897 | fdb_kvs_id_t kv_id = 0; |
| 1898 | fdb_kvs_handle *root_handle; |
| 1899 | struct avl_node *a = NULL; |
| 1900 | struct list_elem *e; |
| 1901 | struct filemgr *file; |
| 1902 | struct kvs_node *node, query; |
| 1903 | struct kvs_header *kv_header; |
| 1904 | struct kvs_opened_node *opened_node; |
| 1905 | |
| 1906 | if (!fhandle) { |
| 1907 | return FDB_RESULT_INVALID_HANDLE; |
| 1908 | } |
| 1909 | root_handle = fhandle->root; |
| 1910 | |
| 1911 | if (root_handle->config.multi_kv_instances == false) { |
| 1912 | // cannot remove the KV instance under single DB instance mode |
| 1913 | return FDB_RESULT_INVALID_CONFIG; |
| 1914 | } |
| 1915 | if (root_handle->kvs->type != KVS_ROOT) { |
| 1916 | return FDB_RESULT_INVALID_HANDLE; |
| 1917 | } |
| 1918 | |
| 1919 | fdb_kvs_remove_start: |
| 1920 | if (!rollback_recreate) { |
| 1921 | fdb_check_file_reopen(root_handle, NULL); |
| 1922 | filemgr_mutex_lock(root_handle->file); |
| 1923 | fdb_sync_db_header(root_handle); |
| 1924 | |
| 1925 | if (filemgr_is_rollback_on(root_handle->file)) { |
| 1926 | filemgr_mutex_unlock(root_handle->file); |
| 1927 | return FDB_RESULT_FAIL_BY_ROLLBACK; |
| 1928 | } |
| 1929 | } else { |
| 1930 | filemgr_mutex_lock(root_handle->file); |
| 1931 | } |
| 1932 | |
| 1933 | file = root_handle->file; |
| 1934 | |
| 1935 | file_status_t fstatus = filemgr_get_file_status(file); |
| 1936 | if (fstatus == FILE_REMOVED_PENDING) { |
| 1937 | // we must not write into this file |
| 1938 | // file status was changed by other thread .. start over |
| 1939 | filemgr_mutex_unlock(file); |
| 1940 | goto fdb_kvs_remove_start; |
| 1941 | } else if (fstatus == FILE_COMPACT_OLD) { |
| 1942 | // Cannot remove existing KV store during compaction. |
| 1943 | // To remove a KV store, the corresponding first chunk in HB+trie |
| 1944 | // should be unlinked. This can be possible in the old file during |
| 1945 | // compaction, but impossible in the new file, since existing documents |
| 1946 | // (including docs belonging to the KV store to be removed) are being moved. |
no test coverage detected