implemented support for multiple proxies

This commit is contained in:
Manfred Klimt 2018-06-28 13:25:11 +02:00
parent 82514f2b52
commit 71d7f96944
35 changed files with 156 additions and 111 deletions

View file

@ -91,13 +91,11 @@ XCodecCacheCOSS::~XCodecCacheCOSS()
delete[] directory_;
/*
INFO(log_) << "Stats: ";
INFO(log_) << "\tLookups=" << stats_.lookups;
INFO(log_) << "\tHits=" << (stats_.found_1 + stats_.found_2) << " (" << stats_.found_1 << " + " << stats_.found_2 << ")";
if (stats_.lookups > 0)
INFO(log_) << "\tHit ratio=" << ((stats_.found_1 + stats_.found_2) * 100) / stats_.lookups << "%";
*/
DEBUG(log_) << "Closing coss file: " << file_path_;
DEBUG(log_) << "Serial: " << serial_number_;
@ -195,13 +193,15 @@ bool XCodecCacheCOSS::lookup (const uint64_t& hash, Buffer& buf)
int slot;
stats_.lookups++;
#ifdef USING_XCODEC_CACHE_RECENT_WINDOW
if ((data = find_recent (hash)))
{
buf.append (data, XCODEC_SEGMENT_LENGTH);
stats_.found_1++;
return true;
}
#endif
if (! (entry = cache_index_.lookup (hash)))
return false;
@ -227,7 +227,9 @@ bool XCodecCacheCOSS::lookup (const uint64_t& hash, Buffer& buf)
stripe_[slot].header.flags[entry->position] |= 3;
data = stripe_[slot].segment_array[entry->position].bytes;
#ifdef USING_XCODEC_CACHE_RECENT_WINDOW
remember (hash, data);
#endif
buf.append (data, XCODEC_SEGMENT_LENGTH);
stats_.found_2++;
return true;
@ -337,7 +339,9 @@ void XCodecCacheCOSS::detach_stripe (int slot)
{
if (stripe_[slot].header.flags[i] & 1)
{
#ifdef USING_XCODEC_CACHE_RECENT_WINDOW
forget (stripe_[slot].header.hash_array[i]);
#endif
stripe_[slot].header.flags[i] &= ~1;
}
}

View file

@ -79,7 +79,7 @@ using namespace std;
#define CACHE_SIGNATURE 0xF150E964
#define CACHE_VERSION 2
#define STRIPE_SEGMENT_COUNT 512 // segments of XCODEC_SEGMENT_LENGTH per stripe (must fit into 16 bits)
#define LOADED_STRIPE_COUNT 4 // number of stripes held in memory (must be greater than 1)
#define LOADED_STRIPE_COUNT 16 // number of stripes held in memory (must be greater than 1)
#define CACHE_BASIC_SIZE 1024 // MB
#define CACHE_ALIGNEMENT 4096
@ -89,6 +89,8 @@ using namespace std;
#define HEADER_ALIGNED_SIZE ROUND_UP(HEADER_ARRAY_SIZE + METADATA_SIZE, CACHE_ALIGNEMENT)
#define METADATA_PADDING (HEADER_ALIGNED_SIZE - HEADER_ARRAY_SIZE - METADATA_SIZE)
#define USING_XCODEC_CACHE_RECENT_WINDOW
struct COSSIndexEntry
{
uint64_t stripe_range : 48;

View file

@ -27,7 +27,6 @@
#include <common/endian.h>
#include <common/count_filter.h>
#include <event/event_system.h>
#include <programs/wanproxy/wanproxy.h>
#include "xcodec_filter.h"
////////////////////////////////////////////////////////////////////////////////
@ -239,7 +238,7 @@ bool DecodeFilter::consume (Buffer& buf, int flg)
ERROR(log_) << "Got <HELLO> twice.";
return false;
}
else
else if (codec_)
{
uint8_t len;
if (pending_.length() < sizeof op + sizeof len)
@ -266,7 +265,7 @@ bool DecodeFilter::consume (Buffer& buf, int flg)
pending_.skip (sizeof mb);
if (! (decoder_cache_ = wanproxy.find_cache (uuid)))
decoder_cache_ = wanproxy.add_cache (uuid, mb);
decoder_cache_ = wanproxy.add_cache (codec_->cache_type_, codec_->cache_path_, mb, uuid);
ASSERT(log_, decoder_ == NULL);
if (decoder_cache_)

View file

@ -20,11 +20,13 @@
#include <xcodec/xcodec_hash.h>
#include <xcodec/xcodec_encoder.h>
#include <xcodec/xcodec_decoder.h>
#include <proxy/wanproxy.h>
class EncodeFilter : public BufferedFilter
{
private:
XCodecCache* cache_;
WANProxyCodec* codec_;
XCodecCache* cache_;
XCodecEncoder* encoder_;
Action* wait_action_;
bool waiting_;
@ -32,9 +34,10 @@ private:
bool eos_ack_;
public:
EncodeFilter (const LogHandle& log, XCodecCache* cc, int flg = 0) : BufferedFilter (log)
EncodeFilter (const LogHandle& log, WANProxyCodec* cdc, int flg = 0) : BufferedFilter (log)
{
cache_ = cc; encoder_ = 0; wait_action_ = 0; waiting_ = (flg & 1); sent_eos_ = eos_ack_ = false;
codec_ = cdc; cache_ = (cdc ? cdc->xcache_ : 0); encoder_ = 0;
wait_action_ = 0; waiting_ = (flg & 1); sent_eos_ = eos_ack_ = false;
}
virtual ~EncodeFilter ()
@ -55,7 +58,8 @@ private:
class DecodeFilter : public LogisticFilter
{
private:
XCodecCache* encoder_cache_;
WANProxyCodec* codec_;
XCodecCache* encoder_cache_;
XCodecDecoder* decoder_;
XCodecCache* decoder_cache_;
std::set<uint64_t> unknown_hashes_;
@ -66,9 +70,9 @@ private:
bool upflushed_;
public:
DecodeFilter (const LogHandle& log, XCodecCache* cc) : LogisticFilter (log)
DecodeFilter (const LogHandle& log, WANProxyCodec* cdc) : LogisticFilter (log)
{
encoder_cache_ = cc; decoder_ = 0; decoder_cache_ = 0;
codec_ = cdc; encoder_cache_ = (cdc ? cdc->xcache_ : 0); decoder_ = 0; decoder_cache_ = 0;
received_eos_ = sent_eos_ack_ = received_eos_ack_ = upflushed_ = false;
}