40 #if defined FIX8_HAVE_LIBMEMCACHED
46 bool MemcachedPersister::initialise(
const f8String& config_str,
const f8String& key_base,
bool purge)
51 _cache = memcached(config_str.c_str(), config_str.size());
52 if (!(_server_count = memcached_server_count(_cache)))
54 glout_error <<
"Error: no memcached servers were configured for " << _key_base;
57 return purge ? memcached_success(memcached_flush(_cache, 0)) : true;
61 MemcachedPersister::~MemcachedPersister()
63 memcached_free(_cache);
68 unsigned MemcachedPersister::get_last_seqnum(
unsigned& sequence)
const
70 unsigned sender_seqnum, target_seqnum;
71 return get(sender_seqnum, target_seqnum) ? sequence = sender_seqnum : 0;
75 unsigned MemcachedPersister::get(
const unsigned from,
const unsigned to,
Session& session,
79 get_last_seqnum(last_seq);
80 unsigned recs_sent(0), startSeqNum(find_nearest_highest_seqnum (from, last_seq));
81 const unsigned finish(to == 0 ? last_seq : to);
84 if (!startSeqNum || from > finish)
92 for (; startSeqNum <= finish; ++startSeqNum)
94 string target, key(generate_seq_key(startSeqNum));
95 if (get_from_cache(key, target))
99 if (!(session.*callback)(txresult, rctx))
111 bool MemcachedPersister::put(
const unsigned sender_seqnum,
const unsigned target_seqnum)
115 const string key(generate_seq_key(0)), payload(generate_ctrl_record(sender_seqnum, target_seqnum));
116 if (!put_to_cache(key, payload))
118 glout_error <<
"Error: could not write control record to memcached for " << _key_base;
125 bool MemcachedPersister::put(
const unsigned seqnum,
const f8String& what)
127 if (!_cache || !seqnum)
130 const string key(generate_seq_key(seqnum));
131 if (!put_to_cache(key, what))
133 glout_error <<
"Error: could not write record for seqnum " << seqnum <<
" for " << _key_base;
146 const string key(_key_base + inkey);
147 if (!put_to_cache(key, what))
149 glout_error <<
"Error: could not write record for key " << inkey <<
" for " << _key_base;
157 bool MemcachedPersister::get(
unsigned& sender_seqnum,
unsigned& target_seqnum)
const
162 const string key(generate_seq_key(0));
164 if (!get_from_cache(key, target))
166 glout_warn <<
"Warning: memcached does not have control record for " << _key_base;
170 extract_ctrl_record(target, sender_seqnum, target_seqnum);
175 bool MemcachedPersister::get(
const unsigned seqnum,
f8String& to)
const
177 if (!_cache || !seqnum)
179 const string key(generate_seq_key(seqnum));
180 if (!get_from_cache(key, to))
182 glout_warn <<
"Warning: could not get message record with seqnum " << seqnum <<
" for " << _key_base;
194 const string key(_key_base + inkey);
195 if (!get_from_cache(key, to))
197 glout_warn <<
"Warning: could not get message record with key " << inkey <<
" for " << _key_base;
205 unsigned MemcachedPersister::find_nearest_highest_seqnum (
const unsigned requested,
const unsigned last)
const
209 for (
unsigned startseqnum(requested); startseqnum <= last; ++startseqnum)
212 if (
get(startseqnum, target))
221 unsigned MemcachedPersister::find_nearest_seqnum (
unsigned requested)
const
223 for (; requested > 0; --requested)
226 if (
get(requested, target))
233 #endif // FIX8_HAVE_LIBMEMCACHED
Fix8 Base Session. User sessions are derived from this class.
std::pair< const unsigned, const f8String > SequencePair
Provides context to your retrans handler.
unsigned get_next_send_seq() const