43 "Invalid value for MAX VERSIONS (%d), must be non-negative",
46 if (m_counter && max_versions != 0)
48 "COUNTER and MAX VERSIONS are incompatible");
50 m_isset.set(MAX_VERSIONS);
52 if (m_max_versions != max_versions) {
53 m_max_versions = max_versions;
60 return m_isset.test(MAX_VERSIONS);
67 "Invalid value for TTL (%d), must be non-negative", (
int)ttl);
77 return m_isset.test(TTL);
85 "COUNTER and TIME_ORDER_DESC are incompatible");
87 m_isset.set(TIME_ORDER_DESC);
88 if (m_time_order_desc != value) {
89 m_time_order_desc = value;
97 return m_isset.test(TIME_ORDER_DESC);
105 "COUNTER and MAX_VERSIONS are incompatible");
106 if (m_time_order_desc)
108 "COUNTER and TIME_ORDER_DESC are incompatible");
110 m_isset.set(COUNTER);
111 if (m_counter != value) {
119 return m_isset.test(COUNTER);
136 class XmlParserColumnFamilyOptions :
public XmlParser {
139 int len) :
XmlParser(s,len), m_options(ops) {}
141 void end_element(
const XML_Char *name,
const string &content)
override {
142 if (!strcasecmp(name,
"MaxVersions"))
143 m_options->set_max_versions(content_to_i32(name, content));
144 else if (!strcasecmp(name,
"TTL"))
145 m_options->set_ttl((time_t)content_to_i32(name, content));
146 else if (!strcasecmp(name,
"TimeOrder"))
147 m_options->set_time_order_desc(content_to_text(name, content,
148 {
"asc",
"desc"})==
"desc");
149 else if (!strcasecmp(name,
"Counter"))
150 m_options->set_counter(content_to_bool(name, content));
151 else if (!m_element_stack.empty())
153 "Unrecognized ColumnFamily option element (%s)", name);
162 XmlParserColumnFamilyOptions parser(
this, base, len);
168 if (is_set_max_versions())
169 xstr +=
format(
"%s<MaxVersions>%d</MaxVersions>\n",
170 line_prefix.c_str(), (int)m_max_versions);
172 xstr +=
format(
"%s<TTL>%d</TTL>\n", line_prefix.c_str(), (int)m_ttl);
173 if (is_set_time_order_desc())
174 xstr +=
format(
"%s<TimeOrder>%s</TimeOrder>\n", line_prefix.c_str(),
175 m_time_order_desc ?
"desc" :
"asc");
176 if (is_set_counter())
177 xstr +=
format(
"%s<Counter>%s</Counter>\n", line_prefix.c_str(),
178 m_counter ?
"true" :
"false");
184 if (is_set_max_versions())
185 hstr +=
format(
" MAX_VERSIONS %d", (
int)m_max_versions);
187 hstr +=
format(
" TTL %d", (
int)m_ttl);
188 if (is_set_time_order_desc())
189 hstr +=
format(
" TIME_ORDER %s", m_time_order_desc ?
"desc" :
"asc");
190 if (is_set_counter())
191 hstr +=
format(
" COUNTER %s", m_counter ?
"true" :
"false");
196 return (m_isset == other.
m_isset &&
198 m_ttl == other.
m_ttl &&
212 m_generation = generation;
220 if (m_deleted != value) {
227 if (m_options.set_max_versions(max_versions))
232 if (m_options.set_ttl(ttl))
237 if (m_options.set_time_order_desc(value))
246 "COUNTER and INDEX are incompatible");
247 if (m_qualifier_index)
249 "COUNTER and QUALIFIER INDEX are incompatible");
252 if (m_options.set_counter(value))
257 if (value && m_options.get_counter())
259 "COUNTER and INDEX are incompatible");
260 if (m_value_index != value) {
261 m_value_index = value;
267 if (value && m_options.get_counter())
269 "COUNTER and QUALIFIER INDEX are incompatible");
270 if (m_qualifier_index != value) {
271 m_qualifier_index = value;
277 m_options.merge(other);
281 return (m_name == other.
m_name &&
282 m_ag == other.
m_ag &&
284 m_id == other.
m_id &&
294 class XmlParserColumnFamilySpec :
public XmlParser {
297 XmlParser(s,len,{
"Options"}), m_spec(spec) {}
299 void start_element(
const XML_Char *name,
const XML_Char **atts)
override {
300 if (m_element_stack.empty()) {
301 for (
int i=0; atts[i] != 0; i+=2) {
302 if (!strcasecmp(atts[i],
"id"))
303 m_spec->set_id(content_to_i32(
"id", atts[i+1]));
306 "Unrecognized attribute (%s) in ColumnFamily element", atts[i]);
311 void end_element(
const XML_Char *name,
const string &content)
override {
312 if (!strcasecmp(name,
"Name"))
313 m_spec->set_name(content);
314 else if (!strcasecmp(name,
"AccessGroup"))
315 m_spec->set_access_group(content);
316 else if (!strcasecmp(name,
"Generation"))
317 m_generation = content_to_i64(name, content);
318 else if (!strcasecmp(name,
"Deleted"))
319 m_spec->set_deleted(content_to_bool(name, content));
320 else if (!strcasecmp(name,
"Index"))
321 m_spec->set_value_index(content_to_bool(name, content));
322 else if (!strcasecmp(name,
"QualifierIndex"))
323 m_spec->set_qualifier_index(content_to_bool(name, content));
324 else if (m_element_stack.empty())
325 m_spec->set_generation(m_generation);
328 if (!strcasecmp(name,
"MaxVersions"))
329 m_spec->set_option_max_versions(content_to_i32(name, content));
330 else if (!strcasecmp(name,
"TTL"))
331 m_spec->set_option_ttl((time_t)content_to_i32(name, content));
332 else if (!strcasecmp(name,
"TimeOrder")) {
333 bool val = content_to_text(name, content, {
"asc",
"desc"}) ==
"desc";
334 m_spec->set_option_time_order_desc(val);
336 else if (!strcasecmp(name,
"Counter"))
337 m_spec->set_option_counter(content_to_bool(name, content));
338 else if (!strcasecmp(name,
"Renamed") || !strcasecmp(name,
"NewName"))
342 "Unrecognized ColumnFamily element (%s)", name);
346 void sub_parse(
const XML_Char *name,
const char *s,
int len)
override {
348 XmlParserColumnFamilyOptions parser(&options, s, len);
350 m_spec->merge_options(options);
355 int64_t m_generation {};
361 XmlParserColumnFamilySpec parser(
this, base, len);
366 bool with_ids)
const {
368 stack<string> prefix;
369 prefix.push(line_prefix);
370 output += prefix.top() +
"<ColumnFamily";
371 prefix.push(prefix.top() +
" ");
373 output +=
format(
" id=\"%u\"", get_id());
375 output += prefix.top() +
format(
"<Generation>%lld</Generation>\n", (
Lld)get_generation());
379 output += prefix.top() +
format(
"<Name>%s</Name>\n", get_name().c_str());
380 output += prefix.top() +
format(
"<AccessGroup>%s</AccessGroup>\n", get_access_group().c_str());
381 output += prefix.top() +
format(
"<Deleted>%s</Deleted>\n",
382 get_deleted() ?
"true" :
"false");
383 if (get_value_index())
384 output += prefix.top() +
format(
"<Index>true</Index>\n");
385 if (get_qualifier_index())
386 output += prefix.top() +
format(
"<QualifierIndex>true</QualifierIndex>\n");
387 output += prefix.top() +
format(
"<Options>\n");
388 prefix.push(prefix.top() +
" ");
389 output += options().render_xml(prefix.top());
391 output += prefix.top() +
format(
"</Options>\n");
393 output += prefix.top() +
"</ColumnFamily>\n";
398 const std::string maybe_quote(
const string &name) {
399 auto valid_char = [](
char c) {
return isalnum(c); };
400 if (!isalpha(name[0]) ||
401 find_if_not(name.begin(), name.end(), valid_char) != name.end())
402 return String(
"'") + name +
"'";
413 output +=
format(
" %s", maybe_quote(get_name()).c_str());
415 output += options().render_hql();
417 if (get_value_index())
418 output +=
format(
", INDEX %s", maybe_quote(get_name()).c_str());
420 if (get_qualifier_index())
421 output +=
format(
", QUALIFIER INDEX %s", maybe_quote(get_name()).c_str());
bool get_counter() const
Gets the counter option.
void set_id(int32_t id)
Sets column ID.
bool is_set_max_versions() const
Checks if max versions option is set.
bool get_time_order_desc() const
Gets time order desc option.
bool is_set_ttl() const
Checks if ttl option is set.
const std::string render_xml(const std::string &line_prefix, bool with_ids=false) const
Renders spec in XML format.
void parse_xml(const char *base, int len)
Parses XML options document.
std::string m_ag
Access group name.
ColumnFamilyOptions m_options
Options.
void set_option_max_versions(int32_t max_versions)
Sets max versions option.
void set_generation(int64_t generation)
Sets generation.
std::string String
A String is simply a typedef to std::string.
bool set_max_versions(int32_t max_versions)
Sets max versions option.
bool m_value_index
Value index flag.
void set_deleted(bool value)
Sets deleted flag.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
const std::string render_hql() const
Renders options in HQL format.
Column family specification.
int32_t m_max_versions
Max version.
void set_qualifier_index(bool value)
Sets qualifier index flag.
void set_name(const std::string &name)
Sets column family name.
const std::string render_hql() const
Renders spec in HQL format.
bool set_ttl(time_t ttl)
Sets ttl option.
Specification for column family options.
void set_option_time_order_desc(bool value)
Sets time order desc option.
bool m_qualifier_index
Qualifier index flag
bool is_set_counter() const
Checks if counter option is set.
void set_value_index(bool value)
Sets value index flag.
bool m_deleted
Deleted flag.
bool operator==(const ColumnFamilySpec &other) const
Equality operator.
void merge_options(const ColumnFamilyOptions &other)
Merges options from another ColumnFamilyOptions object.
Definitions for XmlParser.
void parse_xml(const char *base, int len)
Parses XML options document.
Compatibility Macros for C/C++.
bool set_time_order_desc(bool value)
Sets time order desc option.
std::string m_name
Column family name
int32_t get_max_versions() const
Gets max versions option.
bool set_counter(bool value)
Sets counter option.
void set_option_counter(bool value)
Sets counter option.
bool is_set_time_order_desc() const
Checks if time_order_desc option is set.
void merge(const ColumnFamilyOptions &other)
Merges options from another ColumnFamilyOptions object.
time_t get_ttl() const
Gets ttl option.
void set_option_ttl(time_t ttl)
Sets ttl option.
long long int Lld
Shortcut for printf formats.
std::bitset< MAX > m_isset
Bit mask describing which options are set.
Base class for XML document parsers.
void set_access_group(const std::string &ag)
Sets access group.
#define HT_THROWF(_code_, _fmt_,...)
const std::string render_xml(const std::string &line_prefix) const
Renders options in XML format.
int64_t m_generation
Generation.
bool operator==(const ColumnFamilyOptions &other) const
Equality operator.
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
Declarations for ColumnFamilySpec.
bool m_time_order_desc
Time order "desc" flag.