CUBRID Engine  latest
lob_locator.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 //
20 // Lob locator implementation
21 //
22 
23 #include "lob_locator.hpp"
24 
25 #if defined (CS_MODE)
26 #include "network_interface_cl.h"
27 #endif
28 #include "porting.h"
29 #if !defined (CS_MODE)
31 #endif
32 
33 #include <cstring>
34 #include <string>
35 
36 bool
37 lob_locator_is_valid (const char *locator)
38 {
39  if (locator == NULL)
40  {
41  return false;
42  }
43  const char *key = lob_locator_key (locator);
44  const char *meta = lob_locator_meta (locator);
45  if (key == NULL || meta == NULL || key - 1 <= meta)
46  {
47  return false;
48  }
49  // is valid
50  return true;
51 }
52 
53 const char *
54 lob_locator_key (const char *locator)
55 {
56  return std::strrchr (locator, '.') + 1;
57 }
58 
59 const char *
60 lob_locator_meta (const char *locator)
61 {
62  return std::strrchr (locator, PATH_SEPARATOR);
63 }
64 
65 /*
66  * lob_locator_find () - wrapper function
67  * return: LOB_LOCATOR_STATE
68  * locator(in):
69  * real_locator(out):
70  */
72 lob_locator_find (const char *locator, char *real_locator)
73 {
74 #if defined(CS_MODE)
75  return log_find_lob_locator (locator, real_locator);
76 #else /* CS_MODE */
77  return xtx_find_lob_locator (NULL, locator, real_locator);
78 #endif /* CS_MODE */
79 }
80 
81 /*
82  * lob_locator_add () - wrapper function
83  * return: error status
84  * locator(in):
85  * state(in):
86  */
87 int
88 lob_locator_add (const char *locator, LOB_LOCATOR_STATE state)
89 {
90 #if defined(CS_MODE)
91  return log_add_lob_locator (locator, state);
92 #else /* CS_MODE */
93  return xtx_add_lob_locator (NULL, locator, state);
94 #endif /* CS_MODE */
95 }
96 
97 /*
98  * lob_locator_change_state () - wrapper function
99  * return: error status
100  * locator(in):
101  * new_locator(in):
102  * state(in):
103  */
104 int
105 lob_locator_change_state (const char *locator, const char *new_locator, LOB_LOCATOR_STATE state)
106 {
107 #if defined(CS_MODE)
108  return log_change_state_of_locator (locator, new_locator, state);
109 #else /* CS_MODE */
110  return xtx_change_state_of_locator (NULL, locator, new_locator, state);
111 #endif /* CS_MODE */
112 }
113 
114 /*
115  * lob_locator_drop () - wrapper function
116  * return: error status
117  * locator(in):
118  */
119 int
120 lob_locator_drop (const char *locator)
121 {
122 #if defined(CS_MODE)
123  return log_drop_lob_locator (locator);
124 #else /* CS_MODE */
125  return xtx_drop_lob_locator (NULL, locator);
126 #endif /* CS_MODE */
127 }
int lob_locator_change_state(const char *locator, const char *new_locator, LOB_LOCATOR_STATE state)
int xtx_add_lob_locator(cubthread::entry *thread_p, const char *locator, LOB_LOCATOR_STATE state)
int xtx_drop_lob_locator(cubthread::entry *thread_p, const char *locator)
bool lob_locator_is_valid(const char *locator)
Definition: lob_locator.cpp:37
#define NULL
Definition: freelistheap.h:34
LOB_LOCATOR_STATE lob_locator_find(const char *locator, char *real_locator)
Definition: lob_locator.cpp:72
const char * lob_locator_key(const char *locator)
Definition: lob_locator.cpp:54
int lob_locator_add(const char *locator, LOB_LOCATOR_STATE state)
Definition: lob_locator.cpp:88
enum lob_locator_state LOB_LOCATOR_STATE
Definition: lob_locator.hpp:62
int xtx_change_state_of_locator(cubthread::entry *thread_p, const char *locator, const char *new_locator, LOB_LOCATOR_STATE state)
#define PATH_SEPARATOR
Definition: porting.h:347
LOB_LOCATOR_STATE xtx_find_lob_locator(cubthread::entry *thread_p, const char *locator, char *real_locator)
int lob_locator_drop(const char *locator)
const char * lob_locator_meta(const char *locator)
Definition: lob_locator.cpp:60