You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by su...@apache.org on 2015/09/14 21:22:14 UTC
trafficserver git commit: [TS-3881] new TS API TSHttpTxnInfoGet.
Repository: trafficserver
Updated Branches:
refs/heads/master ce415f5de -> b5673f75c
[TS-3881] new TS API TSHttpTxnInfoGet.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/b5673f75
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/b5673f75
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/b5673f75
Branch: refs/heads/master
Commit: b5673f75c53cf3f7d077dba7db558f6224ffc6ad
Parents: ce415f5
Author: Sudheer Vinukonda <su...@yahoo-inc.com>
Authored: Mon Sep 14 19:21:24 2015 +0000
Committer: Sudheer Vinukonda <su...@yahoo-inc.com>
Committed: Mon Sep 14 19:21:24 2015 +0000
----------------------------------------------------------------------
iocore/cache/Cache.cc | 4 ++-
iocore/cache/I_Cache.h | 13 ++++++++++
iocore/cache/P_CacheInternal.h | 15 +++++++++++
iocore/cache/RamCacheCLFUS.cc | 6 ++++-
lib/ts/apidefs.h.in | 11 ++++++++
proxy/InkAPI.cc | 35 +++++++++++++++++++++++++
proxy/InkAPITest.cc | 51 +++++++++++++++++++++++++++++++++++++
proxy/api/ts/experimental.h | 13 ++++++++++
proxy/http/HttpCacheSM.h | 42 ++++++++++++++++++++++++++++++
9 files changed, 188 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b5673f75/iocore/cache/Cache.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index 2e57525..1fa4284 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -2459,7 +2459,9 @@ CacheVC::handleRead(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
// check ram cache
ink_assert(vol->mutex->thread_holding == this_ethread());
int64_t o = dir_offset(&dir);
- if (vol->ram_cache->get(read_key, &buf, (uint32_t)(o >> 32), (uint32_t)o)) {
+ int ram_hit_state = vol->ram_cache->get(read_key, &buf, (uint32_t)(o >> 32), (uint32_t)o);
+ f.compressed_in_ram = (ram_hit_state > RAM_HIT_COMPRESS_NONE) ? 1 : 0;
+ if (ram_hit_state >= RAM_HIT_COMPRESS_NONE) {
goto LramHit;
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b5673f75/iocore/cache/I_Cache.h
----------------------------------------------------------------------
diff --git a/iocore/cache/I_Cache.h b/iocore/cache/I_Cache.h
index de06a44..eb8bdbd 100644
--- a/iocore/cache/I_Cache.h
+++ b/iocore/cache/I_Cache.h
@@ -49,6 +49,8 @@
#define CACHE_COMPRESSION_LIBZ 2
#define CACHE_COMPRESSION_LIBLZMA 3
+enum { RAM_HIT_COMPRESS_NONE = 1, RAM_HIT_COMPRESS_FASTLZ, RAM_HIT_COMPRESS_LIBZ, RAM_HIT_COMPRESS_LIBLZMA, RAM_HIT_LAST_ENTRY };
+
struct CacheVC;
struct CacheDisk;
#ifdef HTTP_CACHE
@@ -204,6 +206,17 @@ struct CacheVConnection : public VConnection {
virtual bool set_pin_in_cache(time_t t) = 0;
virtual time_t get_pin_in_cache() = 0;
virtual int64_t get_object_size() = 0;
+ virtual bool
+ is_compressed_in_ram() const
+ {
+ return false;
+ }
+
+ virtual int
+ get_volume_number() const
+ {
+ return -1;
+ }
/** Test if the VC can support pread.
@return @c true if @c do_io_pread will work, @c false if not.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b5673f75/iocore/cache/P_CacheInternal.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index 74efade..b3858d2 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -269,6 +269,20 @@ struct CacheVC : public CacheVConnection {
}
return -1;
}
+ int
+ get_volume_number() const
+ {
+ if (vol && vol->cache_vol) {
+ return vol->cache_vol->vol_number;
+ }
+ return -1;
+ }
+ bool
+ is_compressed_in_ram() const
+ {
+ ink_assert(vio.op == VIO::READ);
+ return !f.compressed_in_ram;
+ }
bool writer_done();
int calluser(int event);
@@ -477,6 +491,7 @@ struct CacheVC : public CacheVConnection {
unsigned int readers : 1;
unsigned int doc_from_ram_cache : 1;
unsigned int hit_evacuate : 1;
+ unsigned int compressed_in_ram : 1; // compressed state in ram cache
#ifdef HTTP_CACHE
unsigned int allow_empty_doc : 1; // used for cache empty http document
#endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b5673f75/iocore/cache/RamCacheCLFUS.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/RamCacheCLFUS.cc b/iocore/cache/RamCacheCLFUS.cc
index 8eb72ce..db44527 100644
--- a/iocore/cache/RamCacheCLFUS.cc
+++ b/iocore/cache/RamCacheCLFUS.cc
@@ -220,6 +220,7 @@ RamCacheCLFUS::get(INK_MD5 *key, Ptr<IOBufferData> *ret_data, uint32_t auxkey1,
lru[e->flag_bits.lru].remove(e);
lru[e->flag_bits.lru].enqueue(e);
if (!e->flag_bits.lru) { // in memory
+ uint32_t ram_hit_state = RAM_HIT_COMPRESS_NONE;
e->hits++;
if (e->flag_bits.compressed) {
b = (char *)ats_malloc(e->len);
@@ -230,6 +231,7 @@ RamCacheCLFUS::get(INK_MD5 *key, Ptr<IOBufferData> *ret_data, uint32_t auxkey1,
int l = (int)e->len;
if ((l != (int)fastlz_decompress(e->data->data(), e->compressed_len, b, l)))
goto Lfailed;
+ ram_hit_state = RAM_HIT_COMPRESS_FASTLZ;
break;
}
#if TS_HAS_LIBZ
@@ -237,6 +239,7 @@ RamCacheCLFUS::get(INK_MD5 *key, Ptr<IOBufferData> *ret_data, uint32_t auxkey1,
uLongf l = e->len;
if (Z_OK != uncompress((Bytef *)b, &l, (Bytef *)e->data->data(), e->compressed_len))
goto Lfailed;
+ ram_hit_state = RAM_HIT_COMPRESS_LIBZ;
break;
}
#endif
@@ -247,6 +250,7 @@ RamCacheCLFUS::get(INK_MD5 *key, Ptr<IOBufferData> *ret_data, uint32_t auxkey1,
if (LZMA_OK != lzma_stream_buffer_decode(&memlimit, 0, NULL, (uint8_t *)e->data->data(), &ipos, e->compressed_len,
(uint8_t *)b, &opos, l))
goto Lfailed;
+ ram_hit_state = RAM_HIT_COMPRESS_LIBLZMA;
break;
}
#endif
@@ -273,7 +277,7 @@ RamCacheCLFUS::get(INK_MD5 *key, Ptr<IOBufferData> *ret_data, uint32_t auxkey1,
}
CACHE_SUM_DYN_STAT_THREAD(cache_ram_cache_hits_stat, 1);
DDebug("ram_cache", "get %X %d %d size %d HIT", key->slice32(3), auxkey1, auxkey2, e->size);
- return 1;
+ return ram_hit_state;
} else {
CACHE_SUM_DYN_STAT_THREAD(cache_ram_cache_misses_stat, 1);
DDebug("ram_cache", "get %X %d %d HISTORY", key->slice32(3), auxkey1, auxkey2);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b5673f75/lib/ts/apidefs.h.in
----------------------------------------------------------------------
diff --git a/lib/ts/apidefs.h.in b/lib/ts/apidefs.h.in
index 174ac0e..48bd64a 100644
--- a/lib/ts/apidefs.h.in
+++ b/lib/ts/apidefs.h.in
@@ -493,6 +493,17 @@ typedef enum {
TS_CACHE_SCAN_RESULT_RETRY
} TSCacheScanResult;
+typedef enum {
+ TS_TXN_INFO_NONE = -1,
+ TS_TXN_INFO_CACHE_HIT_RAM,
+ TS_TXN_INFO_COMPRESSED_IN_RAM,
+ TS_TXN_INFO_CACHE_HIT_RWW, // READ_WHILE_WRITE
+ TS_TXN_INFO_CACHE_OPEN_READ_TRIES,
+ TS_TXN_INFO_CACHE_OPEN_WRITE_TRIES,
+ TS_TXN_INFO_CACHE_VOLUME,
+ TS_TXN_INFO_LAST_ENTRY
+} TSHttpTxnInfoKey;
+
typedef enum { TS_VC_CLOSE_ABORT = -1, TS_VC_CLOSE_NORMAL = 1 } TSVConnCloseFlags;
typedef enum {
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b5673f75/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 923ae29..0c736de 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -4833,6 +4833,41 @@ TSHttpTxnCacheLookupStatusSet(TSHttpTxn txnp, int cachelookup)
}
TSReturnCode
+TSHttpTxnInfoGet(TSHttpTxn txnp, TSHttpTxnInfoKey key, TSMgmtInt *value)
+{
+ sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
+ sdk_assert(sdk_sanity_check_null_ptr((void *)value) == TS_SUCCESS);
+
+ HttpSM *s = reinterpret_cast<HttpSM *>(txnp);
+ HttpCacheSM *c_sm = &(s->get_cache_sm());
+
+ switch (key) {
+ case TS_TXN_INFO_CACHE_HIT_RAM:
+ *value = (static_cast<TSMgmtInt>(c_sm->is_ram_cache_hit()));
+ break;
+ case TS_TXN_INFO_COMPRESSED_IN_RAM:
+ *value = (static_cast<TSMgmtInt>(c_sm->is_compressed_in_ram()));
+ break;
+ case TS_TXN_INFO_CACHE_HIT_RWW:
+ *value = (static_cast<TSMgmtInt>(c_sm->is_readwhilewrite_inprogress()));
+ break;
+ case TS_TXN_INFO_CACHE_OPEN_READ_TRIES:
+ *value = (static_cast<TSMgmtInt>(c_sm->get_open_read_tries()));
+ break;
+ case TS_TXN_INFO_CACHE_OPEN_WRITE_TRIES:
+ *value = (static_cast<TSMgmtInt>(c_sm->get_open_write_tries()));
+ break;
+ case TS_TXN_INFO_CACHE_VOLUME:
+ *value = (static_cast<TSMgmtInt>(c_sm->get_volume_number()));
+ break;
+ default:
+ return TS_ERROR;
+ }
+
+ return TS_SUCCESS;
+}
+
+TSReturnCode
TSHttpTxnCacheLookupUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj)
{
sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b5673f75/proxy/InkAPITest.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPITest.cc b/proxy/InkAPITest.cc
index 968e990..dd57d34 100644
--- a/proxy/InkAPITest.cc
+++ b/proxy/InkAPITest.cc
@@ -7298,6 +7298,57 @@ REGRESSION_TEST(SDK_API_OVERRIDABLE_CONFIGS)(RegressionTest *test, int /* atype
}
////////////////////////////////////////////////
+// SDK_API_TXN_HTTP_INFO_GET
+//
+// Unit Test for API: TSHttpTxnInfoGet
+////////////////////////////////////////////////
+
+REGRESSION_TEST(SDK_API_TXN_HTTP_INFO_GET)(RegressionTest *test, int /* atype ATS_UNUSED */, int *pstatus)
+{
+ HttpSM *s = HttpSM::allocate();
+ bool success = true;
+ TSHttpTxn txnp = reinterpret_cast<TSHttpTxn>(s);
+ TSMgmtInt ival_read;
+
+
+ s->init();
+
+ *pstatus = REGRESSION_TEST_INPROGRESS;
+ HttpCacheSM *c_sm = &(s->get_cache_sm());
+ c_sm->set_readwhilewrite_inprogress(true);
+ c_sm->set_open_read_tries(5);
+ c_sm->set_open_write_tries(8);
+
+ TSHttpTxnInfoGet(txnp, TS_TXN_INFO_CACHE_HIT_RWW, &ival_read);
+ if (ival_read == 0) {
+ SDK_RPRINT(test, "TSHttpTxnInfoGet", "TestCase1", TC_FAIL, "Failed on %d, %d != %d", TS_TXN_INFO_CACHE_HIT_RWW, ival_read, 1);
+ success = false;
+ }
+
+ TSHttpTxnInfoGet(txnp, TS_TXN_INFO_CACHE_OPEN_READ_TRIES, &ival_read);
+ if (ival_read != 5) {
+ SDK_RPRINT(test, "TSHttpTxnInfoGet", "TestCase1", TC_FAIL, "Failed on %d, %d != %d", TS_TXN_INFO_CACHE_HIT_RWW, ival_read, 5);
+ success = false;
+ }
+
+ TSHttpTxnInfoGet(txnp, TS_TXN_INFO_CACHE_OPEN_WRITE_TRIES, &ival_read);
+ if (ival_read != 8) {
+ SDK_RPRINT(test, "TSHttpTxnInfoGet", "TestCase1", TC_FAIL, "Failed on %d, %d != %d", TS_TXN_INFO_CACHE_HIT_RWW, ival_read, 8);
+ success = false;
+ }
+
+ s->destroy();
+ if (success) {
+ *pstatus = REGRESSION_TEST_PASSED;
+ SDK_RPRINT(test, "TSHttpTxnInfoGet", "TestCase1", TC_PASS, "ok");
+ } else {
+ *pstatus = REGRESSION_TEST_FAILED;
+ }
+
+ return;
+}
+
+////////////////////////////////////////////////
// SDK_API_ENCODING
//
// Unit Test for API: TSStringPercentEncode
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b5673f75/proxy/api/ts/experimental.h
----------------------------------------------------------------------
diff --git a/proxy/api/ts/experimental.h b/proxy/api/ts/experimental.h
index ee4fd57..ebe43c0 100644
--- a/proxy/api/ts/experimental.h
+++ b/proxy/api/ts/experimental.h
@@ -188,6 +188,19 @@ tsapi void TSCacheHttpInfoReqGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc
tsapi void TSCacheHttpInfoRespGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *offset);
tsapi void TSCacheHttpInfoDestroy(TSCacheHttpInfo infop);
+/* Get Arbitrary Txn info such as cache lookup details etc as defined in TSHttpTxnInfoKey */
+/**
+ Return the particular txn info requested.
+
+ @param txnp the transaction pointer
+ @param key the requested txn info.
+ @param TSMgmtInt a pointer to a integer where the return value is stored
+
+ @return @c TS_SUCCESS if the requested info is supported, TS_ERROR otherwise
+
+*/
+tsapi TSReturnCode TSHttpTxnInfoGet(TSHttpTxn txnp, TSHttpTxnInfoKey key, TSMgmtInt *value);
+
/* ===== ICP ===== */
tsapi void TSHttpIcpDynamicSet(int value);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b5673f75/proxy/http/HttpCacheSM.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpCacheSM.h b/proxy/http/HttpCacheSM.h
index 3c14da3..9190d2a 100644
--- a/proxy/http/HttpCacheSM.h
+++ b/proxy/http/HttpCacheSM.h
@@ -98,6 +98,48 @@ public:
return readwhilewrite_inprogress;
}
+ bool
+ is_ram_cache_hit()
+ {
+ return cache_read_vc ? (cache_read_vc->is_ram_cache_hit()) : 0;
+ }
+
+ bool
+ is_compressed_in_ram()
+ {
+ return cache_read_vc ? (cache_read_vc->is_compressed_in_ram()) : 0;
+ }
+
+ inline void
+ set_open_read_tries(int value)
+ {
+ open_read_tries = value;
+ }
+
+ int
+ get_open_read_tries()
+ {
+ return open_read_tries;
+ }
+
+ inline void
+ set_open_write_tries(int value)
+ {
+ open_write_tries = value;
+ }
+
+ int
+ get_open_write_tries()
+ {
+ return open_write_tries;
+ }
+
+ int
+ get_volume_number()
+ {
+ return cache_read_vc ? (cache_read_vc->get_volume_number()) : -1;
+ }
+
inline void
abort_read()
{