http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/cache/I_Store.h ---------------------------------------------------------------------- diff --git a/iocore/cache/I_Store.h b/iocore/cache/I_Store.h index c49ab38..6ebfd6e 100644 --- a/iocore/cache/I_Store.h +++ b/iocore/cache/I_Store.h @@ -33,12 +33,11 @@ #include "libts.h" -#define STORE_BLOCK_SIZE 8192 -#define STORE_BLOCK_SHIFT 13 +#define STORE_BLOCK_SIZE 8192 +#define STORE_BLOCK_SHIFT 13 #define DEFAULT_HW_SECTOR_SIZE 512 -enum span_error_t -{ +enum span_error_t { SPAN_ERROR_OK, SPAN_ERROR_UNKNOWN, SPAN_ERROR_NOT_FOUND, @@ -48,50 +47,57 @@ enum span_error_t SPAN_ERROR_MEDIA_PROBE, }; -struct span_diskid_t -{ +struct span_diskid_t { int64_t id[2]; - bool operator < (const span_diskid_t& rhs) const { - return id[0] < rhs.id[0] && id[1] < rhs.id[1]; - } + bool operator<(const span_diskid_t &rhs) const { return id[0] < rhs.id[0] && id[1] < rhs.id[1]; } - bool operator == (const span_diskid_t& rhs) const { - return id[0] == rhs.id[0] && id[1] == rhs.id[1]; - } + bool operator==(const span_diskid_t &rhs) const { return id[0] == rhs.id[0] && id[1] == rhs.id[1]; } - int64_t& operator[] (unsigned i) { - return id[i]; - } + int64_t &operator[](unsigned i) { return id[i]; } }; // // A Store is a place to store data. // Those on the same disk should be in a linked list. // -struct Span -{ - int64_t blocks; // in STORE_BLOCK_SIZE blocks - int64_t offset; // used only if (file == true); in bytes +struct Span { + int64_t blocks; // in STORE_BLOCK_SIZE blocks + int64_t offset; // used only if (file == true); in bytes unsigned hw_sector_size; unsigned alignment; span_diskid_t disk_id; - int forced_volume_num; ///< Force span in to specific volume. + int forced_volume_num; ///< Force span in to specific volume. private: bool is_mmapable_internal; + public: - bool file_pathname; // the pathname is a file + bool file_pathname; // the pathname is a file // v- used as a magic location for copy constructor. // we memcpy everything before this member and do explicit assignment for the rest. ats_scoped_str pathname; ats_scoped_str hash_base_string; ///< Used to seed the stripe assignment hash. SLINK(Span, link); - bool is_mmapable() const { return is_mmapable_internal; } - void set_mmapable(bool s) { is_mmapable_internal = s; } - int64_t size() const { return blocks * STORE_BLOCK_SIZE; } + bool + is_mmapable() const + { + return is_mmapable_internal; + } + void + set_mmapable(bool s) + { + is_mmapable_internal = s; + } + int64_t + size() const + { + return blocks * STORE_BLOCK_SIZE; + } - int64_t total_blocks() const { + int64_t + total_blocks() const + { if (link.next) { return blocks + link.next->total_blocks(); } else { @@ -99,16 +105,21 @@ public: } } - Span *nth(unsigned i) { + Span * + nth(unsigned i) + { Span *x = this; while (x && i--) x = x->link.next; return x; } - unsigned paths() const { + unsigned + paths() const + { int i = 0; - for (const Span * x = this; x; i++, x = x->link.next); + for (const Span *x = this; x; i++, x = x->link.next) + ; return i; } @@ -117,28 +128,27 @@ public: /// Duplicate this span and all chained spans. Span *dup(); - int64_t end() const { return offset + blocks; } + int64_t + end() const + { + return offset + blocks; + } const char *init(const char *n, int64_t size); // 0 on success -1 on failure - int path(char *filename, // for non-file, the filename in the director - int64_t * offset, // for file, start offset (unsupported) - char *buf, int buflen); // where to store the path + int path(char *filename, // for non-file, the filename in the director + int64_t *offset, // for file, start offset (unsupported) + char *buf, int buflen); // where to store the path /// Set the hash seed string. - void hash_base_string_set(char const* s); + void hash_base_string_set(char const *s); /// Set the volume number. void volume_number_set(int n); Span() - : blocks(0) - , offset(0) - , hw_sector_size(DEFAULT_HW_SECTOR_SIZE) - , alignment(0) - , forced_volume_num(-1) - , is_mmapable_internal(false) - , file_pathname(false) + : blocks(0), offset(0), hw_sector_size(DEFAULT_HW_SECTOR_SIZE), alignment(0), forced_volume_num(-1), + is_mmapable_internal(false), file_pathname(false) { disk_id[0] = disk_id[1] = 0; } @@ -146,51 +156,56 @@ public: /// Copy constructor. /// @internal Prior to this implementation handling the char* pointers was done manual /// at every call site. We also need this because we have ats_scoped_str members. - Span(Span const& that) { - memcpy(this, &that, reinterpret_cast<intptr_t>(&(static_cast<Span*>(0)->pathname))); - if (that.pathname) pathname = ats_strdup(that.pathname); - if (that.hash_base_string) hash_base_string = ats_strdup(that.hash_base_string); + Span(Span const &that) + { + memcpy(this, &that, reinterpret_cast<intptr_t>(&(static_cast<Span *>(0)->pathname))); + if (that.pathname) + pathname = ats_strdup(that.pathname); + if (that.hash_base_string) + hash_base_string = ats_strdup(that.hash_base_string); link.next = NULL; } ~Span(); - static const char * errorstr(span_error_t serr); + static const char *errorstr(span_error_t serr); }; -struct Store -{ +struct Store { // // Public Interface // Thread-safe operations // // spread evenly on all disks - void spread_alloc(Store & s, unsigned int blocks, bool mmapable = true); - void alloc(Store & s, unsigned int blocks, bool only_one = false, bool mmapable = true); + void spread_alloc(Store &s, unsigned int blocks, bool mmapable = true); + void alloc(Store &s, unsigned int blocks, bool only_one = false, bool mmapable = true); - Span *alloc_one(unsigned int blocks, bool mmapable) { + Span * + alloc_one(unsigned int blocks, bool mmapable) + { Store s; alloc(s, blocks, true, mmapable); if (s.n_disks) { Span *t = s.disk[0]; - s.disk[0] = NULL; - return t; + s.disk[0] = NULL; + return t; } return NULL; } // try to allocate, return (s == gotten, diff == not gotten) - void try_realloc(Store & s, Store & diff); + void try_realloc(Store &s, Store &diff); // free back the contents of a store. // must have been JUST allocated (no intervening allocs/frees) - void free(Store & s); - void add(Span * s); - void add(Store & s); - void dup(Store & s); + void free(Store &s); + void add(Span *s); + void add(Store &s); + void dup(Store &s); void sort(); - void extend(unsigned i) + void + extend(unsigned i) { if (i > n_disks) { disk = (Span **)ats_realloc(disk, i * sizeof(Span *)); @@ -202,14 +217,16 @@ struct Store } // Non Thread-safe operations - unsigned int total_blocks(unsigned after = 0) const { + unsigned int + total_blocks(unsigned after = 0) const + { int64_t t = 0; for (unsigned i = after; i < n_disks; i++) { if (disk[i]) { t += disk[i]->total_blocks(); } } - return (unsigned int) t; + return (unsigned int)t; } // 0 on success -1 on failure // these operations are NOT thread-safe @@ -244,6 +261,6 @@ struct Store }; // store either free or in the cache, can be stolen for reconfiguration -void stealStore(Store & s, int blocks); +void stealStore(Store &s, int blocks); #endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/cache/Inline.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/Inline.cc b/iocore/cache/Inline.cc index c1b63c4..ecd72d2 100644 --- a/iocore/cache/Inline.cc +++ b/iocore/cache/Inline.cc @@ -28,5 +28,3 @@ #define TS_INLINE #include "P_Cache.h" - - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/cache/P_CacheArray.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheArray.h b/iocore/cache/P_CacheArray.h index 681290a..69a1feb 100644 --- a/iocore/cache/P_CacheArray.h +++ b/iocore/cache/P_CacheArray.h @@ -24,22 +24,22 @@ #ifndef __CACHE_ARRAY_H__ #define __CACHE_ARRAY_H__ -#define FAST_DATA_SIZE 4 +#define FAST_DATA_SIZE 4 -template<class T> struct CacheArray -{ - CacheArray(const T * val, int initial_size = 0); - ~CacheArray(); +template <class T> struct CacheArray { + CacheArray(const T *val, int initial_size = 0); + ~CacheArray(); - operator const T *() const; - operator T *(); - T & operator[] (int idx); - T & operator() (int idx); + operator const T *() const; + operator T *(); + T &operator[](int idx); + T &operator()(int idx); T *detach(); int length(); void clear(); - void set_length(int i) + void + set_length(int i) { pos = i - 1; } @@ -54,12 +54,10 @@ template<class T> struct CacheArray }; -template<class T> TS_INLINE CacheArray<T>::CacheArray(const T * val, int initial_size) - : -data(NULL), -default_val(val), -size(0), -pos(-1) +template <class T> +TS_INLINE +CacheArray<T>::CacheArray(const T *val, int initial_size) + : data(NULL), default_val(val), size(0), pos(-1) { if (initial_size > 0) { int i = 1; @@ -71,32 +69,32 @@ pos(-1) } } -template<class T> TS_INLINE CacheArray<T>::~CacheArray() +template <class T> TS_INLINE CacheArray<T>::~CacheArray() { if (data) { if (data != fast_data) { - delete[]data; + delete[] data; } } } -template<class T> TS_INLINE CacheArray<T>::operator const T *() -const +template <class T> TS_INLINE CacheArray<T>::operator const T *() const { - return - data; + return data; } -template <class T> TS_INLINE CacheArray <T>::operator T *() +template <class T> TS_INLINE CacheArray<T>::operator T *() { return data; } -template<class T> TS_INLINE T & CacheArray<T>::operator [](int idx) { +template <class T> TS_INLINE T &CacheArray<T>::operator[](int idx) +{ return data[idx]; } -template<class T> TS_INLINE T & CacheArray<T>::operator ()(int idx) { +template <class T> TS_INLINE T &CacheArray<T>::operator()(int idx) +{ if (idx >= size) { int new_size; @@ -120,7 +118,9 @@ template<class T> TS_INLINE T & CacheArray<T>::operator ()(int idx) { return data[idx]; } -template<class T> TS_INLINE T * CacheArray<T>::detach() +template <class T> +TS_INLINE T * +CacheArray<T>::detach() { T *d; @@ -130,16 +130,20 @@ template<class T> TS_INLINE T * CacheArray<T>::detach() return d; } -template<class T> TS_INLINE int CacheArray<T>::length() +template <class T> +TS_INLINE int +CacheArray<T>::length() { return pos + 1; } -template<class T> TS_INLINE void CacheArray<T>::clear() +template <class T> +TS_INLINE void +CacheArray<T>::clear() { if (data) { if (data != fast_data) { - delete[]data; + delete[] data; } data = NULL; } @@ -148,7 +152,9 @@ template<class T> TS_INLINE void CacheArray<T>::clear() pos = -1; } -template<class T> TS_INLINE void CacheArray<T>::resize(int new_size) +template <class T> +TS_INLINE void +CacheArray<T>::resize(int new_size) { if (new_size > size) { T *new_data; @@ -170,7 +176,7 @@ template<class T> TS_INLINE void CacheArray<T>::resize(int new_size) if (data) { if (data != fast_data) { - delete[]data; + delete[] data; } } data = new_data; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/cache/P_CacheBC.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheBC.h b/iocore/cache/P_CacheBC.h index cc1c400..2164692 100644 --- a/iocore/cache/P_CacheBC.h +++ b/iocore/cache/P_CacheBC.h @@ -25,105 +25,117 @@ #ifndef _P_CACHE_BC_H__ #define _P_CACHE_BC_H__ -namespace cache_bc { - - /* This looks kind of dumb, but I think it's useful. We import external structure - dependencies in to this namespace so we can at least (1) notice them and - (2) change them if the current structure changes. - */ - - typedef HTTPHdr HTTPHdr_v21; - typedef HdrHeap HdrHeap_v23; - typedef CryptoHash CryptoHash_v23; - typedef HTTPCacheAlt HTTPCacheAlt_v23; - - /** Cache backwards compatibility structure - the fragment table. - This is copied from @c HTTPCacheAlt in @c HTTP.h. - */ - struct HTTPCacheFragmentTable { - /// # of fragment offsets in this alternate. - /// @note This is one less than the number of fragments. - int m_frag_offset_count; - /// Type of offset for a fragment. - typedef uint64_t FragOffset; - /// Table of fragment offsets. - /// @note The offsets are forward looking so that frag[0] is the - /// first byte past the end of fragment 0 which is also the first - /// byte of fragment 1. For this reason there is no fragment offset - /// for the last fragment. - FragOffset *m_frag_offsets; - /// # of fragment offsets built in to object. - static int const N_INTEGRAL_FRAG_OFFSETS = 4; - /// Integral fragment offset table. - FragOffset m_integral_frag_offsets[N_INTEGRAL_FRAG_OFFSETS]; - }; - - // From before moving the fragment table to the alternate. - struct HTTPCacheAlt_v21 +namespace cache_bc +{ +/* This looks kind of dumb, but I think it's useful. We import external structure + dependencies in to this namespace so we can at least (1) notice them and + (2) change them if the current structure changes. +*/ + +typedef HTTPHdr HTTPHdr_v21; +typedef HdrHeap HdrHeap_v23; +typedef CryptoHash CryptoHash_v23; +typedef HTTPCacheAlt HTTPCacheAlt_v23; + +/** Cache backwards compatibility structure - the fragment table. + This is copied from @c HTTPCacheAlt in @c HTTP.h. +*/ +struct HTTPCacheFragmentTable { + /// # of fragment offsets in this alternate. + /// @note This is one less than the number of fragments. + int m_frag_offset_count; + /// Type of offset for a fragment. + typedef uint64_t FragOffset; + /// Table of fragment offsets. + /// @note The offsets are forward looking so that frag[0] is the + /// first byte past the end of fragment 0 which is also the first + /// byte of fragment 1. For this reason there is no fragment offset + /// for the last fragment. + FragOffset *m_frag_offsets; + /// # of fragment offsets built in to object. + static int const N_INTEGRAL_FRAG_OFFSETS = 4; + /// Integral fragment offset table. + FragOffset m_integral_frag_offsets[N_INTEGRAL_FRAG_OFFSETS]; +}; + +// From before moving the fragment table to the alternate. +struct HTTPCacheAlt_v21 { + uint32_t m_magic; + + int32_t m_writeable; + int32_t m_unmarshal_len; + + int32_t m_id; + int32_t m_rid; + + int32_t m_object_key[4]; + int32_t m_object_size[2]; + + HTTPHdr_v21 m_request_hdr; + HTTPHdr_v21 m_response_hdr; + + time_t m_request_sent_time; + time_t m_response_received_time; + + RefCountObj *m_ext_buffer; + + // The following methods were added for BC support. + // Checks itself to verify that it is unmarshalled and v21 format. + bool + is_unmarshalled_format() const { - uint32_t m_magic; - - int32_t m_writeable; - int32_t m_unmarshal_len; - - int32_t m_id; - int32_t m_rid; - - int32_t m_object_key[4]; - int32_t m_object_size[2]; - - HTTPHdr_v21 m_request_hdr; - HTTPHdr_v21 m_response_hdr; - - time_t m_request_sent_time; - time_t m_response_received_time; - - RefCountObj *m_ext_buffer; - - // The following methods were added for BC support. - // Checks itself to verify that it is unmarshalled and v21 format. - bool is_unmarshalled_format() const { - return CACHE_ALT_MAGIC_MARSHALED == m_magic && reinterpret_cast<intptr_t>(m_request_hdr.m_heap) == sizeof(*this); - } - }; - - /// Really just a namespace, doesn't depend on any of the members. - struct HTTPInfo_v21 { - typedef uint64_t FragOffset; - /// Version upgrade methods - /// @a src , @a dst , and @a n are updated upon return. - /// @a n is the space in @a dst remaining. - /// @return @c false if something went wrong. - static bool copy_and_upgrade_unmarshalled_to_v23(char*& dst, char*& src, size_t& length, int n_frags, FragOffset* frag_offsets); - /// The size of the marshalled data of a marshalled alternate header. - static size_t marshalled_length(void* data); - }; - - /// Pre version 24. - struct Doc_v23 - { - uint32_t magic; // DOC_MAGIC - uint32_t len; // length of this segment (including hlen, flen & sizeof(Doc), unrounded) - uint64_t total_len; // total length of document - CryptoHash_v23 first_key; ///< first key in object. - CryptoHash_v23 key; ///< Key for this doc. - uint32_t hlen; ///< Length of this header. - uint32_t doc_type:8; ///< Doc type - indicates the format of this structure and its content. - uint32_t _flen:24; ///< Fragment table length. - uint32_t sync_serial; - uint32_t write_serial; - uint32_t pinned; // pinned until - uint32_t checksum; - - char* hdr(); - char* data(); - size_t data_len(); - }; - - static size_t const sizeofDoc_v23 = sizeof(Doc_v23); - char* Doc_v23::data() { return reinterpret_cast<char*>(this) + sizeofDoc_v23 + _flen + hlen; } - size_t Doc_v23::data_len() { return len - sizeofDoc_v23 - hlen; } - char* Doc_v23::hdr() { return reinterpret_cast<char*>(this) + sizeofDoc_v23; } + return CACHE_ALT_MAGIC_MARSHALED == m_magic && reinterpret_cast<intptr_t>(m_request_hdr.m_heap) == sizeof(*this); + } +}; + +/// Really just a namespace, doesn't depend on any of the members. +struct HTTPInfo_v21 { + typedef uint64_t FragOffset; + /// Version upgrade methods + /// @a src , @a dst , and @a n are updated upon return. + /// @a n is the space in @a dst remaining. + /// @return @c false if something went wrong. + static bool copy_and_upgrade_unmarshalled_to_v23(char *&dst, char *&src, size_t &length, int n_frags, FragOffset *frag_offsets); + /// The size of the marshalled data of a marshalled alternate header. + static size_t marshalled_length(void *data); +}; + +/// Pre version 24. +struct Doc_v23 { + uint32_t magic; // DOC_MAGIC + uint32_t len; // length of this segment (including hlen, flen & sizeof(Doc), unrounded) + uint64_t total_len; // total length of document + CryptoHash_v23 first_key; ///< first key in object. + CryptoHash_v23 key; ///< Key for this doc. + uint32_t hlen; ///< Length of this header. + uint32_t doc_type : 8; ///< Doc type - indicates the format of this structure and its content. + uint32_t _flen : 24; ///< Fragment table length. + uint32_t sync_serial; + uint32_t write_serial; + uint32_t pinned; // pinned until + uint32_t checksum; + + char *hdr(); + char *data(); + size_t data_len(); +}; + +static size_t const sizeofDoc_v23 = sizeof(Doc_v23); +char * +Doc_v23::data() +{ + return reinterpret_cast<char *>(this) + sizeofDoc_v23 + _flen + hlen; +} +size_t +Doc_v23::data_len() +{ + return len - sizeofDoc_v23 - hlen; +} +char * +Doc_v23::hdr() +{ + return reinterpret_cast<char *>(this) + sizeofDoc_v23; +} } // namespace cache_bc http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/cache/P_CacheDir.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheDir.h b/iocore/cache/P_CacheDir.h index b63e02b..0a31c32 100644 --- a/iocore/cache/P_CacheDir.h +++ b/iocore/cache/P_CacheDir.h @@ -37,24 +37,24 @@ struct CacheVC; // Constants -#define DIR_TAG_WIDTH 12 -#define DIR_MASK_TAG(_t) ((_t) & ((1 << DIR_TAG_WIDTH) - 1)) -#define SIZEOF_DIR 10 -#define ESTIMATED_OBJECT_SIZE 8000 - -#define MAX_DIR_SEGMENTS (32 * (1<<16)) -#define DIR_DEPTH 4 -#define DIR_SIZE_WIDTH 6 -#define DIR_BLOCK_SIZES 4 -#define DIR_BLOCK_SHIFT(_i) (3*(_i)) -#define DIR_BLOCK_SIZE(_i) (CACHE_BLOCK_SIZE << DIR_BLOCK_SHIFT(_i)) -#define DIR_SIZE_WITH_BLOCK(_i) ((1<<DIR_SIZE_WIDTH) * DIR_BLOCK_SIZE(_i)) -#define DIR_OFFSET_BITS 40 -#define DIR_OFFSET_MAX ((((off_t)1) << DIR_OFFSET_BITS) - 1) - -#define SYNC_MAX_WRITE (2 * 1024 * 1024) -#define SYNC_DELAY HRTIME_MSECONDS(500) -#define DO_NOT_REMOVE_THIS 0 +#define DIR_TAG_WIDTH 12 +#define DIR_MASK_TAG(_t) ((_t) & ((1 << DIR_TAG_WIDTH) - 1)) +#define SIZEOF_DIR 10 +#define ESTIMATED_OBJECT_SIZE 8000 + +#define MAX_DIR_SEGMENTS (32 * (1 << 16)) +#define DIR_DEPTH 4 +#define DIR_SIZE_WIDTH 6 +#define DIR_BLOCK_SIZES 4 +#define DIR_BLOCK_SHIFT(_i) (3 * (_i)) +#define DIR_BLOCK_SIZE(_i) (CACHE_BLOCK_SIZE << DIR_BLOCK_SHIFT(_i)) +#define DIR_SIZE_WITH_BLOCK(_i) ((1 << DIR_SIZE_WIDTH) * DIR_BLOCK_SIZE(_i)) +#define DIR_OFFSET_BITS 40 +#define DIR_OFFSET_MAX ((((off_t)1) << DIR_OFFSET_BITS) - 1) + +#define SYNC_MAX_WRITE (2 * 1024 * 1024) +#define SYNC_DELAY HRTIME_MSECONDS(500) +#define DO_NOT_REMOVE_THIS 0 // Debugging Options @@ -69,49 +69,46 @@ struct CacheVC; #define CHECK_DIR(_d) ((void)0) #endif -#define dir_index(_e, _i) ((Dir*)((char*)(_e)->dir + (SIZEOF_DIR * (_i)))) -#define dir_assign(_e,_x) do { \ - (_e)->w[0] = (_x)->w[0]; \ - (_e)->w[1] = (_x)->w[1]; \ - (_e)->w[2] = (_x)->w[2]; \ - (_e)->w[3] = (_x)->w[3]; \ - (_e)->w[4] = (_x)->w[4]; \ -} while (0) -#define dir_assign_data(_e,_x) do { \ - unsigned short next = dir_next(_e); \ - dir_assign(_e, _x); \ - dir_set_next(_e, next); \ -} while(0) +#define dir_index(_e, _i) ((Dir *)((char *)(_e)->dir + (SIZEOF_DIR * (_i)))) +#define dir_assign(_e, _x) \ + do { \ + (_e)->w[0] = (_x)->w[0]; \ + (_e)->w[1] = (_x)->w[1]; \ + (_e)->w[2] = (_x)->w[2]; \ + (_e)->w[3] = (_x)->w[3]; \ + (_e)->w[4] = (_x)->w[4]; \ + } while (0) +#define dir_assign_data(_e, _x) \ + do { \ + unsigned short next = dir_next(_e); \ + dir_assign(_e, _x); \ + dir_set_next(_e, next); \ + } while (0) #if !TS_USE_INTERIM_CACHE // entry is valid -#define dir_valid(_d, _e) \ - (_d->header->phase == dir_phase(_e) ? vol_in_phase_valid(_d, _e) : \ - vol_out_of_phase_valid(_d, _e)) +#define dir_valid(_d, _e) (_d->header->phase == dir_phase(_e) ? vol_in_phase_valid(_d, _e) : vol_out_of_phase_valid(_d, _e)) // entry is valid and outside of write aggregation region -#define dir_agg_valid(_d, _e) \ - (_d->header->phase == dir_phase(_e) ? vol_in_phase_valid(_d, _e) : \ - vol_out_of_phase_agg_valid(_d, _e)) +#define dir_agg_valid(_d, _e) (_d->header->phase == dir_phase(_e) ? vol_in_phase_valid(_d, _e) : vol_out_of_phase_agg_valid(_d, _e)) // entry may be valid or overwritten in the last aggregated write -#define dir_write_valid(_d, _e) \ - (_d->header->phase == dir_phase(_e) ? vol_in_phase_valid(_d, _e) : \ - vol_out_of_phase_write_valid(_d, _e)) -#define dir_agg_buf_valid(_d, _e) \ - (_d->header->phase == dir_phase(_e) && vol_in_phase_agg_buf_valid(_d, _e)) +#define dir_write_valid(_d, _e) \ + (_d->header->phase == dir_phase(_e) ? vol_in_phase_valid(_d, _e) : vol_out_of_phase_write_valid(_d, _e)) +#define dir_agg_buf_valid(_d, _e) (_d->header->phase == dir_phase(_e) && vol_in_phase_agg_buf_valid(_d, _e)) #endif #define dir_is_empty(_e) (!dir_offset(_e)) -#define dir_clear(_e) do { \ - (_e)->w[0] = 0; \ - (_e)->w[1] = 0; \ - (_e)->w[2] = 0; \ - (_e)->w[3] = 0; \ - (_e)->w[4] = 0; \ -} while (0) -#define dir_clean(_e) dir_set_offset(_e,0) +#define dir_clear(_e) \ + do { \ + (_e)->w[0] = 0; \ + (_e)->w[1] = 0; \ + (_e)->w[2] = 0; \ + (_e)->w[3] = 0; \ + (_e)->w[4] = 0; \ + } while (0) +#define dir_clean(_e) dir_set_offset(_e, 0) #define dir_segment(_s, _d) vol_dir_segment(_d, _s) // OpenDir -#define OPEN_DIR_BUCKETS 256 +#define OPEN_DIR_BUCKETS 256 struct EvacuationBlock; typedef uint32_t DirInfo; @@ -124,23 +121,22 @@ typedef uint32_t DirInfo; // The accessors prevent unaligned memory access which // is often either less efficient or unsupported depending // on the processor. -struct Dir -{ +struct Dir { #if DO_NOT_REMOVE_THIS // THE BIT-FIELD INTERPRETATION OF THIS STRUCT WHICH HAS TO // USE MACROS TO PREVENT UNALIGNED LOADS // bits are numbered from lowest in u16 to highest // always index as u16 to avoid byte order issues - unsigned int offset:24; // (0,1:0-7) 16M * 512 = 8GB - unsigned int big:2; // (1:8-9) 512 << (3 * big) - unsigned int size:6; // (1:10-15) 6**2 = 64, 64*512 = 32768 .. 64*256=16MB - unsigned int tag:12; // (2:0-11) 2048 / 8 entries/bucket = .4% - unsigned int phase:1; // (2:12) - unsigned int head:1; // (2:13) first segment in a document - unsigned int pinned:1; // (2:14) - unsigned int token:1; // (2:15) - unsigned int next:16; // (3) - inku16 offset_high; // 8GB * 65k = 0.5PB (4) + unsigned int offset : 24; // (0,1:0-7) 16M * 512 = 8GB + unsigned int big : 2; // (1:8-9) 512 << (3 * big) + unsigned int size : 6; // (1:10-15) 6**2 = 64, 64*512 = 32768 .. 64*256=16MB + unsigned int tag : 12; // (2:0-11) 2048 / 8 entries/bucket = .4% + unsigned int phase : 1; // (2:12) + unsigned int head : 1; // (2:13) first segment in a document + unsigned int pinned : 1; // (2:14) + unsigned int token : 1; // (2:15) + unsigned int next : 16; // (3) + inku16 offset_high; // 8GB * 65k = 0.5PB (4) #else uint16_t w[5]; Dir() { dir_clear(this); } @@ -149,21 +145,20 @@ struct Dir // INTERNAL: do not access these members directly, use the // accessors below (e.g. dir_offset, dir_set_offset) -struct FreeDir -{ +struct FreeDir { #if DO_NOT_REMOVE_THIS // THE BIT-FIELD INTERPRETATION OF THIS STRUCT WHICH HAS TO // USE MACROS TO PREVENT UNALIGNED LOADS - unsigned int offset:24; // 0: empty - unsigned int reserved:8; - unsigned int prev:16; // (2) - unsigned int next:16; // (3) + unsigned int offset : 24; // 0: empty + unsigned int reserved : 8; + unsigned int prev : 16; // (2) + unsigned int next : 16; // (3) #if TS_USE_INTERIM_CACHE == 1 - unsigned int offset_high:12; // 8GB * 4K = 32TB - unsigned int index:3; // interim index - unsigned int ininterim:1; // in interim or not + unsigned int offset_high : 12; // 8GB * 4K = 32TB + unsigned int index : 3; // interim index + unsigned int ininterim : 1; // in interim or not #else - inku16 offset_high; // 0: empty + inku16 offset_high; // 0: empty #endif #else uint16_t w[5]; @@ -177,75 +172,75 @@ struct FreeDir #define dir_set_indisk(_e) ((_e)->w[4] &= 0x0FFF); #define dir_get_index(_e) (((_e)->w[4] >> 12) & 0x7) #define dir_set_index(_e, i) ((_e)->w[4] |= (i << 12)) -#define dir_offset(_e) ((int64_t) \ - (((uint64_t)(_e)->w[0]) | \ - (((uint64_t)((_e)->w[1] & 0xFF)) << 16) | \ - (((uint64_t)((_e)->w[4] & 0x0FFF)) << 24))) -#define dir_set_offset(_e, _o) do { \ - (_e)->w[0] = (uint16_t)_o; \ - (_e)->w[1] = (uint16_t)((((_o) >> 16) & 0xFF) | ((_e)->w[1] & 0xFF00)); \ - (_e)->w[4] = (((_e)->w[4] & 0xF000) | ((uint16_t)((_o) >> 24))); \ -} while (0) -#define dir_get_offset(_e) ((int64_t) \ - (((uint64_t)(_e)->w[0]) | \ - (((uint64_t)((_e)->w[1] & 0xFF)) << 16) | \ - (((uint64_t)(_e)->w[4]) << 24))) +#define dir_offset(_e) \ + ((int64_t)(((uint64_t)(_e)->w[0]) | (((uint64_t)((_e)->w[1] & 0xFF)) << 16) | (((uint64_t)((_e)->w[4] & 0x0FFF)) << 24))) +#define dir_set_offset(_e, _o) \ + do { \ + (_e)->w[0] = (uint16_t)_o; \ + (_e)->w[1] = (uint16_t)((((_o) >> 16) & 0xFF) | ((_e)->w[1] & 0xFF00)); \ + (_e)->w[4] = (((_e)->w[4] & 0xF000) | ((uint16_t)((_o) >> 24))); \ + } while (0) +#define dir_get_offset(_e) \ + ((int64_t)(((uint64_t)(_e)->w[0]) | (((uint64_t)((_e)->w[1] & 0xFF)) << 16) | (((uint64_t)(_e)->w[4]) << 24))) void clear_interim_dir(Vol *v); void clear_interimvol_dir(Vol *v, int offset); void dir_clean_range_interimvol(off_t start, off_t end, InterimCacheVol *svol); #else -#define dir_offset(_e) ((int64_t) \ - (((uint64_t)(_e)->w[0]) | \ - (((uint64_t)((_e)->w[1] & 0xFF)) << 16) | \ - (((uint64_t)(_e)->w[4]) << 24))) -#define dir_set_offset(_e,_o) do { \ - (_e)->w[0] = (uint16_t)_o; \ - (_e)->w[1] = (uint16_t)((((_o) >> 16) & 0xFF) | ((_e)->w[1] & 0xFF00)); \ - (_e)->w[4] = (uint16_t)((_o) >> 24); \ -} while (0) +#define dir_offset(_e) \ + ((int64_t)(((uint64_t)(_e)->w[0]) | (((uint64_t)((_e)->w[1] & 0xFF)) << 16) | (((uint64_t)(_e)->w[4]) << 24))) +#define dir_set_offset(_e, _o) \ + do { \ + (_e)->w[0] = (uint16_t)_o; \ + (_e)->w[1] = (uint16_t)((((_o) >> 16) & 0xFF) | ((_e)->w[1] & 0xFF00)); \ + (_e)->w[4] = (uint16_t)((_o) >> 24); \ + } while (0) #endif #define dir_bit(_e, _w, _b) ((uint32_t)(((_e)->w[_w] >> (_b)) & 1)) -#define dir_set_bit(_e, _w, _b, _v) (_e)->w[_w] = (uint16_t)(((_e)->w[_w] & ~(1<<(_b))) | (((_v)?1:0)<<(_b))) -#define dir_big(_e) ((uint32_t)((((_e)->w[1]) >> 8)&0x3)) -#define dir_set_big(_e, _v) (_e)->w[1] = (uint16_t)(((_e)->w[1] & 0xFCFF) | (((uint16_t)(_v))&0x3)<<8) +#define dir_set_bit(_e, _w, _b, _v) (_e)->w[_w] = (uint16_t)(((_e)->w[_w] & ~(1 << (_b))) | (((_v) ? 1 : 0) << (_b))) +#define dir_big(_e) ((uint32_t)((((_e)->w[1]) >> 8) & 0x3)) +#define dir_set_big(_e, _v) (_e)->w[1] = (uint16_t)(((_e)->w[1] & 0xFCFF) | (((uint16_t)(_v)) & 0x3) << 8) #define dir_size(_e) ((uint32_t)(((_e)->w[1]) >> 10)) -#define dir_set_size(_e, _v) (_e)->w[1] = (uint16_t)(((_e)->w[1] & ((1<<10)-1)) | ((_v)<<10)) -#define dir_set_approx_size(_e, _s) do { \ - if ((_s) <= DIR_SIZE_WITH_BLOCK(0)) { \ - dir_set_big(_e,0); \ - dir_set_size(_e,((_s)-1) / DIR_BLOCK_SIZE(0)); \ - } else if ((_s) <= DIR_SIZE_WITH_BLOCK(1)) { \ - dir_set_big(_e,1); \ - dir_set_size(_e,((_s)-1) / DIR_BLOCK_SIZE(1)); \ - } else if ((_s) <= DIR_SIZE_WITH_BLOCK(2)) { \ - dir_set_big(_e,2); \ - dir_set_size(_e,((_s)-1) / DIR_BLOCK_SIZE(2)); \ - } else { \ - dir_set_big(_e,3); \ - dir_set_size(_e,((_s)-1) / DIR_BLOCK_SIZE(3)); \ - } \ -} while (0) +#define dir_set_size(_e, _v) (_e)->w[1] = (uint16_t)(((_e)->w[1] & ((1 << 10) - 1)) | ((_v) << 10)) +#define dir_set_approx_size(_e, _s) \ + do { \ + if ((_s) <= DIR_SIZE_WITH_BLOCK(0)) { \ + dir_set_big(_e, 0); \ + dir_set_size(_e, ((_s)-1) / DIR_BLOCK_SIZE(0)); \ + } else if ((_s) <= DIR_SIZE_WITH_BLOCK(1)) { \ + dir_set_big(_e, 1); \ + dir_set_size(_e, ((_s)-1) / DIR_BLOCK_SIZE(1)); \ + } else if ((_s) <= DIR_SIZE_WITH_BLOCK(2)) { \ + dir_set_big(_e, 2); \ + dir_set_size(_e, ((_s)-1) / DIR_BLOCK_SIZE(2)); \ + } else { \ + dir_set_big(_e, 3); \ + dir_set_size(_e, ((_s)-1) / DIR_BLOCK_SIZE(3)); \ + } \ + } while (0) #define dir_approx_size(_e) ((dir_size(_e) + 1) * DIR_BLOCK_SIZE(dir_big(_e))) -#define round_to_approx_dir_size(_s) (_s <= DIR_SIZE_WITH_BLOCK(0) ? ROUND_TO(_s, DIR_BLOCK_SIZE(0)) : \ - (_s <= DIR_SIZE_WITH_BLOCK(1) ? ROUND_TO(_s, DIR_BLOCK_SIZE(1)) : \ - (_s <= DIR_SIZE_WITH_BLOCK(2) ? ROUND_TO(_s, DIR_BLOCK_SIZE(2)) : \ - ROUND_TO(_s, DIR_BLOCK_SIZE(3))))) -#define dir_tag(_e) ((uint32_t)((_e)->w[2]&((1<<DIR_TAG_WIDTH)-1))) -#define dir_set_tag(_e,_t) (_e)->w[2] = (uint16_t)(((_e)->w[2]&~((1<<DIR_TAG_WIDTH)-1)) | ((_t)&((1<<DIR_TAG_WIDTH)-1))) -#define dir_phase(_e) dir_bit(_e,2,12) -#define dir_set_phase(_e,_v) dir_set_bit(_e,2,12,_v) -#define dir_head(_e) dir_bit(_e,2,13) -#define dir_set_head(_e, _v) dir_set_bit(_e,2,13,_v) -#define dir_pinned(_e) dir_bit(_e,2,14) -#define dir_set_pinned(_e, _v) dir_set_bit(_e,2,14,_v) -#define dir_token(_e) dir_bit(_e,2,15) -#define dir_set_token(_e, _v) dir_set_bit(_e,2,15,_v) +#define round_to_approx_dir_size(_s) \ + (_s <= DIR_SIZE_WITH_BLOCK(0) ? \ + ROUND_TO(_s, DIR_BLOCK_SIZE(0)) : \ + (_s <= DIR_SIZE_WITH_BLOCK(1) ? \ + ROUND_TO(_s, DIR_BLOCK_SIZE(1)) : \ + (_s <= DIR_SIZE_WITH_BLOCK(2) ? ROUND_TO(_s, DIR_BLOCK_SIZE(2)) : ROUND_TO(_s, DIR_BLOCK_SIZE(3))))) +#define dir_tag(_e) ((uint32_t)((_e)->w[2] & ((1 << DIR_TAG_WIDTH) - 1))) +#define dir_set_tag(_e, _t) \ + (_e)->w[2] = (uint16_t)(((_e)->w[2] & ~((1 << DIR_TAG_WIDTH) - 1)) | ((_t) & ((1 << DIR_TAG_WIDTH) - 1))) +#define dir_phase(_e) dir_bit(_e, 2, 12) +#define dir_set_phase(_e, _v) dir_set_bit(_e, 2, 12, _v) +#define dir_head(_e) dir_bit(_e, 2, 13) +#define dir_set_head(_e, _v) dir_set_bit(_e, 2, 13, _v) +#define dir_pinned(_e) dir_bit(_e, 2, 14) +#define dir_set_pinned(_e, _v) dir_set_bit(_e, 2, 14, _v) +#define dir_token(_e) dir_bit(_e, 2, 15) +#define dir_set_token(_e, _v) dir_set_bit(_e, 2, 15, _v) #define dir_next(_e) (_e)->w[3] #define dir_set_next(_e, _o) (_e)->w[3] = (uint16_t)(_o) #define dir_prev(_e) (_e)->w[2] -#define dir_set_prev(_e,_o) (_e)->w[2] = (uint16_t)(_o) +#define dir_set_prev(_e, _o) (_e)->w[2] = (uint16_t)(_o) // INKqa11166 - Cache can not store 2 HTTP alternates simultaneously. // To allow this, move the vector from the CacheVC to the OpenDirEntry. @@ -254,36 +249,35 @@ void dir_clean_range_interimvol(off_t start, off_t end, InterimCacheVol *svol); // is deleted/inserted into the vector just before writing the vector disk // (CacheVC::updateVector). LINK_FORWARD_DECLARATION(CacheVC, opendir_link) // forward declaration -struct OpenDirEntry -{ - DLL<CacheVC, Link_CacheVC_opendir_link> writers; // list of all the current writers - DLL<CacheVC, Link_CacheVC_opendir_link> readers; // list of all the current readers - not used - CacheHTTPInfoVector vector; // Vector for the http document. Each writer - // maintains a pointer to this vector and - // writes it down to disk. - CacheKey single_doc_key; // Key for the resident alternate. - Dir single_doc_dir; // Directory for the resident alternate - Dir first_dir; // Dir for the vector. If empty, a new dir is - // inserted, otherwise this dir is overwritten - uint16_t num_writers; // num of current writers - uint16_t max_writers; // max number of simultaneous writers allowed - bool dont_update_directory; // if set, the first_dir is not updated. - bool move_resident_alt; // if set, single_doc_dir is inserted. - volatile bool reading_vec; // somebody is currently reading the vector - volatile bool writing_vec; // somebody is currently writing the vector +struct OpenDirEntry { + DLL<CacheVC, Link_CacheVC_opendir_link> writers; // list of all the current writers + DLL<CacheVC, Link_CacheVC_opendir_link> readers; // list of all the current readers - not used + CacheHTTPInfoVector vector; // Vector for the http document. Each writer + // maintains a pointer to this vector and + // writes it down to disk. + CacheKey single_doc_key; // Key for the resident alternate. + Dir single_doc_dir; // Directory for the resident alternate + Dir first_dir; // Dir for the vector. If empty, a new dir is + // inserted, otherwise this dir is overwritten + uint16_t num_writers; // num of current writers + uint16_t max_writers; // max number of simultaneous writers allowed + bool dont_update_directory; // if set, the first_dir is not updated. + bool move_resident_alt; // if set, single_doc_dir is inserted. + volatile bool reading_vec; // somebody is currently reading the vector + volatile bool writing_vec; // somebody is currently writing the vector LINK(OpenDirEntry, link); int wait(CacheVC *c, int msec); - bool has_multiple_writers() + bool + has_multiple_writers() { return num_writers > 1; } }; -struct OpenDir: public Continuation -{ +struct OpenDir : public Continuation { Queue<CacheVC, Link_CacheVC_opendir_link> delayed_readers; DLL<OpenDirEntry> bucket[OPEN_DIR_BUCKETS]; @@ -295,8 +289,7 @@ struct OpenDir: public Continuation OpenDir(); }; -struct CacheSync: public Continuation -{ +struct CacheSync : public Continuation { int vol_idx; char *buf; size_t buflen; @@ -307,7 +300,7 @@ struct CacheSync: public Continuation int mainEvent(int event, Event *e); void aio_write(int fd, char *b, int n, off_t o); - CacheSync():Continuation(new_ProxyMutex()), vol_idx(0), buf(0), buflen(0), writepos(0), trigger(0), start_time(0) + CacheSync() : Continuation(new_ProxyMutex()), vol_idx(0), buf(0), buflen(0), writepos(0), trigger(0), start_time(0) { SET_HANDLER(&CacheSync::mainEvent); } @@ -321,7 +314,7 @@ int dir_probe(CacheKey *, Vol *, Dir *, Dir **); int dir_insert(CacheKey *key, Vol *d, Dir *to_part); int dir_overwrite(CacheKey *key, Vol *d, Dir *to_part, Dir *overwrite, bool must_overwrite = true); int dir_delete(CacheKey *key, Vol *d, Dir *del); -int dir_lookaside_probe(CacheKey *key, Vol *d, Dir *result, EvacuationBlock ** eblock); +int dir_lookaside_probe(CacheKey *key, Vol *d, Dir *result, EvacuationBlock **eblock); int dir_lookaside_insert(EvacuationBlock *b, Vol *d, Dir *to); int dir_lookaside_fixup(CacheKey *key, Vol *d); void dir_lookaside_cleanup(Vol *d); @@ -331,9 +324,8 @@ void dir_sync_init(); int check_dir(Vol *d); void dir_clean_vol(Vol *d); void dir_clear_range(off_t start, off_t end, Vol *d); -int dir_segment_accounted(int s, Vol *d, int offby = 0, - int *free = 0, int *used = 0, - int *empty = 0, int *valid = 0, int *agg_valid = 0, int *avg_size = 0); +int dir_segment_accounted(int s, Vol *d, int offby = 0, int *free = 0, int *used = 0, int *empty = 0, int *valid = 0, + int *agg_valid = 0, int *avg_size = 0); uint64_t dir_entries_used(Vol *d); void sync_cache_dir_on_shutdown(); @@ -343,7 +335,7 @@ extern Dir empty_dir; // Inline Funtions -#define dir_in_seg(_s, _i) ((Dir*)(((char*)(_s)) + (SIZEOF_DIR *(_i)))) +#define dir_in_seg(_s, _i) ((Dir *)(((char *)(_s)) + (SIZEOF_DIR * (_i)))) TS_INLINE bool dir_compare_tag(Dir *e, CacheKey *key) @@ -373,9 +365,9 @@ TS_INLINE int64_t dir_to_offset(Dir *d, Dir *seg) { #if DIR_DEPTH < 5 - return (((char*)d) - ((char*)seg))/SIZEOF_DIR; + return (((char *)d) - ((char *)seg)) / SIZEOF_DIR; #else - int64_t i = (int64_t)((((char*)d) - ((char*)seg))/SIZEOF_DIR); + int64_t i = (int64_t)((((char *)d) - ((char *)seg)) / SIZEOF_DIR); i = i - (i / DIR_DEPTH); return i; #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/cache/P_CacheDisk.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheDisk.h b/iocore/cache/P_CacheDisk.h index a197435..8b51de2 100644 --- a/iocore/cache/P_CacheDisk.h +++ b/iocore/cache/P_CacheDisk.h @@ -28,70 +28,63 @@ extern int cache_config_max_disk_errors; -#define DISK_BAD(_x) ((_x)->num_errors >= cache_config_max_disk_errors) -#define DISK_BAD_SIGNALLED(_x) (_x->num_errors > cache_config_max_disk_errors) -#define SET_DISK_BAD(_x) (_x->num_errors = cache_config_max_disk_errors) -#define SET_DISK_OKAY(_x) (_x->num_errors = 0) +#define DISK_BAD(_x) ((_x)->num_errors >= cache_config_max_disk_errors) +#define DISK_BAD_SIGNALLED(_x) (_x->num_errors > cache_config_max_disk_errors) +#define SET_DISK_BAD(_x) (_x->num_errors = cache_config_max_disk_errors) +#define SET_DISK_OKAY(_x) (_x->num_errors = 0) -#define VOL_BLOCK_SIZE (1024 * 1024 * 128) -#define MIN_VOL_SIZE VOL_BLOCK_SIZE -#define ROUND_DOWN_TO_VOL_BLOCK(_x) (((_x) &~ (VOL_BLOCK_SIZE - 1))) -#define VOL_BLOCK_SHIFT 27 -#define ROUND_DOWN_TO_STORE_BLOCK(_x) (((_x) >> STORE_BLOCK_SHIFT) << STORE_BLOCK_SHIFT) +#define VOL_BLOCK_SIZE (1024 * 1024 * 128) +#define MIN_VOL_SIZE VOL_BLOCK_SIZE +#define ROUND_DOWN_TO_VOL_BLOCK(_x) (((_x) & ~(VOL_BLOCK_SIZE - 1))) +#define VOL_BLOCK_SHIFT 27 +#define ROUND_DOWN_TO_STORE_BLOCK(_x) (((_x) >> STORE_BLOCK_SHIFT) << STORE_BLOCK_SHIFT) -#define STORE_BLOCKS_PER_VOL (VOL_BLOCK_SIZE / STORE_BLOCK_SIZE) -#define DISK_HEADER_MAGIC 0xABCD1237 +#define STORE_BLOCKS_PER_VOL (VOL_BLOCK_SIZE / STORE_BLOCK_SIZE) +#define DISK_HEADER_MAGIC 0xABCD1237 /* each disk vol block has a corresponding Vol object */ struct CacheDisk; -struct DiskVolBlock -{ - uint64_t offset; // offset in bytes from the start of the disk - uint64_t len; // length in in store blocks +struct DiskVolBlock { + uint64_t offset; // offset in bytes from the start of the disk + uint64_t len; // length in in store blocks int number; - unsigned int type:3; - unsigned int free:1; + unsigned int type : 3; + unsigned int free : 1; }; -struct DiskVolBlockQueue -{ +struct DiskVolBlockQueue { DiskVolBlock *b; - int new_block; /* whether an existing vol or a new one */ + int new_block; /* whether an existing vol or a new one */ LINK(DiskVolBlockQueue, link); - DiskVolBlockQueue() - : b(NULL), new_block(0) - { } + DiskVolBlockQueue() : b(NULL), new_block(0) {} }; -struct DiskVol -{ - int num_volblocks; /* number of disk volume blocks in this volume */ - int vol_number; /* the volume number of this volume */ - uint64_t size; /* size in store blocks */ +struct DiskVol { + int num_volblocks; /* number of disk volume blocks in this volume */ + int vol_number; /* the volume number of this volume */ + uint64_t size; /* size in store blocks */ CacheDisk *disk; Queue<DiskVolBlockQueue> dpb_queue; }; -struct DiskHeader -{ +struct DiskHeader { unsigned int magic; - unsigned int num_volumes; /* number of discrete volumes (DiskVol) */ - unsigned int num_free; /* number of disk volume blocks free */ - unsigned int num_used; /* number of disk volume blocks in use */ - unsigned int num_diskvol_blks; /* number of disk volume blocks */ + unsigned int num_volumes; /* number of discrete volumes (DiskVol) */ + unsigned int num_free; /* number of disk volume blocks free */ + unsigned int num_used; /* number of disk volume blocks in use */ + unsigned int num_diskvol_blks; /* number of disk volume blocks */ uint64_t num_blocks; DiskVolBlock vol_info[1]; }; -struct CacheDisk: public Continuation -{ +struct CacheDisk : public Continuation { DiskHeader *header; char *path; int header_len; AIOCallbackInternal io; - off_t len; // in blocks (STORE_BLOCK) + off_t len; // in blocks (STORE_BLOCK) off_t start; off_t skip; off_t num_usable_blocks; @@ -105,18 +98,16 @@ struct CacheDisk: public Continuation int cleared; // Extra configuration values - int forced_volume_num; ///< Volume number for this disk. + int forced_volume_num; ///< Volume number for this disk. ats_scoped_str hash_base_string; ///< Base string for hash seed. CacheDisk() - : Continuation(new_ProxyMutex()), header(NULL), - path(NULL), header_len(0), len(0), start(0), skip(0), - num_usable_blocks(0), fd(-1), free_space(0), wasted_space(0), - disk_vols(NULL), free_blocks(NULL), num_errors(0), cleared(0), - forced_volume_num(-1) - { } + : Continuation(new_ProxyMutex()), header(NULL), path(NULL), header_len(0), len(0), start(0), skip(0), num_usable_blocks(0), + fd(-1), free_space(0), wasted_space(0), disk_vols(NULL), free_blocks(NULL), num_errors(0), cleared(0), forced_volume_num(-1) + { + } - ~CacheDisk(); + ~CacheDisk(); int open(bool clear); int open(char *s, off_t blocks, off_t skip, int hw_sector_size, int fildes, bool clear); @@ -131,7 +122,6 @@ struct CacheDisk: public Continuation int delete_all_volumes(); void update_header(); DiskVol *get_diskvol(int vol_number); - }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/cache/P_CacheHosting.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheHosting.h b/iocore/cache/P_CacheHosting.h index ce376cc..21d2b1a 100644 --- a/iocore/cache/P_CacheHosting.h +++ b/iocore/cache/P_CacheHosting.h @@ -25,7 +25,7 @@ #define __P_CACHE_HOSTING_H__ #include "P_Cache.h" -#define CACHE_MEM_FREE_TIMEOUT HRTIME_SECONDS(1) +#define CACHE_MEM_FREE_TIMEOUT HRTIME_SECONDS(1) struct Vol; struct CacheVol; @@ -33,8 +33,7 @@ struct CacheVol; struct CacheHostResult; struct Cache; -struct CacheHostRecord -{ +struct CacheHostRecord { int Init(CacheType typ); int Init(matcher_line *line_info, CacheType typ); void UpdateMatch(CacheHostResult *r, char *rd); @@ -55,46 +54,55 @@ struct CacheHostRecord CacheVol **cp; int num_cachevols; - CacheHostRecord(): - type(CACHE_NONE_TYPE), vols(NULL), good_num_vols(0), num_vols(0), - num_initialized(0), vol_hash_table(0), cp(NULL), num_cachevols(0) - { } - + CacheHostRecord() + : type(CACHE_NONE_TYPE), vols(NULL), good_num_vols(0), num_vols(0), num_initialized(0), vol_hash_table(0), cp(NULL), + num_cachevols(0) + { + } }; void build_vol_hash_table(CacheHostRecord *cp); -struct CacheHostResult -{ +struct CacheHostResult { CacheHostRecord *record; - CacheHostResult() - : record(NULL) - { } + CacheHostResult() : record(NULL) {} }; class CacheHostMatcher { public: - CacheHostMatcher(const char * name, CacheType typ); + CacheHostMatcher(const char *name, CacheType typ); ~CacheHostMatcher(); - void Match(char const* rdata, int rlen, CacheHostResult *result); + void Match(char const *rdata, int rlen, CacheHostResult *result); void AllocateSpace(int num_entries); void NewEntry(matcher_line *line_info); void Print(); - int getNumElements() const { return num_el; } - CacheHostRecord *getDataArray() const { return data_array; } - HostLookup *getHLookup() const { return host_lookup; } + int + getNumElements() const + { + return num_el; + } + CacheHostRecord * + getDataArray() const + { + return data_array; + } + HostLookup * + getHLookup() const + { + return host_lookup; + } private: static void PrintFunc(void *opaque_data); - HostLookup *host_lookup; // Data structure to do the lookups - CacheHostRecord *data_array; // array of all data items - int array_len; // the length of the arrays - int num_el; // the number of itmems in the tree + HostLookup *host_lookup; // Data structure to do the lookups + CacheHostRecord *data_array; // array of all data items + int array_len; // the length of the arrays + int num_el; // the number of itmems in the tree CacheType type; }; @@ -104,20 +112,29 @@ public: // Parameter name must not be deallocated before this // object is CacheHostTable(Cache *c, CacheType typ); - ~CacheHostTable(); - int BuildTable(const char * config_file_path); - int BuildTableFromString(const char * config_file_path, char *str); - void Match(char const* rdata, int rlen, CacheHostResult *result); + ~CacheHostTable(); + int BuildTable(const char *config_file_path); + int BuildTableFromString(const char *config_file_path, char *str); + void Match(char const *rdata, int rlen, CacheHostResult *result); void Print(); - int getEntryCount() const { return m_numEntries; } - CacheHostMatcher *getHostMatcher() const { return hostMatch; } + int + getEntryCount() const + { + return m_numEntries; + } + CacheHostMatcher * + getHostMatcher() const + { + return hostMatch; + } static int config_callback(const char *, RecDataT, RecData, void *); - void register_config_callback(CacheHostTable ** p) + void + register_config_callback(CacheHostTable **p) { - REC_RegisterConfigUpdateFunc("proxy.config.cache.hosting_filename", CacheHostTable::config_callback, (void *) p); + REC_RegisterConfigUpdateFunc("proxy.config.cache.hosting_filename", CacheHostTable::config_callback, (void *)p); } CacheType type; @@ -128,26 +145,25 @@ public: private: CacheHostMatcher *hostMatch; const matcher_tags *config_tags; - const char *matcher_name; // Used for Debug/Warning/Error messages + const char *matcher_name; // Used for Debug/Warning/Error messages }; struct CacheHostTableConfig; -typedef int (CacheHostTableConfig::*CacheHostTabHandler) (int, void *); -struct CacheHostTableConfig: public Continuation -{ +typedef int (CacheHostTableConfig::*CacheHostTabHandler)(int, void *); +struct CacheHostTableConfig : public Continuation { CacheHostTable **ppt; - CacheHostTableConfig(CacheHostTable ** appt) - : Continuation(NULL), ppt(appt) + CacheHostTableConfig(CacheHostTable **appt) : Continuation(NULL), ppt(appt) { - SET_HANDLER((CacheHostTabHandler) & CacheHostTableConfig::mainEvent); + SET_HANDLER((CacheHostTabHandler)&CacheHostTableConfig::mainEvent); } - int mainEvent(int event, Event *e) + int + mainEvent(int event, Event *e) { - (void) e; - (void) event; + (void)e; + (void)event; CacheHostTable *t = new CacheHostTable((*ppt)->cache, (*ppt)->type); - CacheHostTable *old = (CacheHostTable *) ink_atomic_swap(&t, *ppt); + CacheHostTable *old = (CacheHostTable *)ink_atomic_swap(&t, *ppt); new_Deleter(old, CACHE_MEM_FREE_TIMEOUT); return EVENT_DONE; } @@ -155,8 +171,7 @@ struct CacheHostTableConfig: public Continuation /* list of volumes in the volume.config file */ -struct ConfigVol -{ +struct ConfigVol { int number; CacheType scheme; off_t size; @@ -166,8 +181,7 @@ struct ConfigVol LINK(ConfigVol, link); }; -struct ConfigVolumes -{ +struct ConfigVolumes { int num_volumes; int num_http_volumes; int num_stream_volumes; @@ -175,7 +189,8 @@ struct ConfigVolumes void read_config_file(); void BuildListFromString(char *config_file_path, char *file_buf); - void clear_all(void) + void + clear_all(void) { // remove all the volumes from the queue for (int i = 0; i < num_volumes; i++) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/cache/P_CacheHttp.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheHttp.h b/iocore/cache/P_CacheHttp.h index e64a200..c5bf87e 100644 --- a/iocore/cache/P_CacheHttp.h +++ b/iocore/cache/P_CacheHttp.h @@ -36,42 +36,40 @@ typedef HTTPInfo CacheHTTPInfo; #define OFFSET_BITS 24 -enum -{ +enum { OWNER_NONE = 0, OWNER_CACHE = 1, - OWNER_HTTP = 2 + OWNER_HTTP = 2, }; #else -struct CacheHTTPInfo -{ +struct CacheHTTPInfo { }; -#endif //HTTP_CACHE +#endif // HTTP_CACHE -struct vec_info -{ +struct vec_info { CacheHTTPInfo alternate; }; -struct CacheHTTPInfoVector -{ +struct CacheHTTPInfoVector { void *magic; - CacheHTTPInfoVector(); - ~CacheHTTPInfoVector(); + CacheHTTPInfoVector(); + ~CacheHTTPInfoVector(); - int count() + int + count() { return xcount; } - int insert(CacheHTTPInfo * info, int id = -1); + int insert(CacheHTTPInfo *info, int id = -1); CacheHTTPInfo *get(int idx); - void detach(int idx, CacheHTTPInfo * r); + void detach(int idx, CacheHTTPInfo *r); void remove(int idx, bool destroy); void clear(bool destroy = true); - void reset() + void + reset() { xcount = 0; data.clear(); @@ -80,8 +78,8 @@ struct CacheHTTPInfoVector int marshal_length(); int marshal(char *buf, int length); - uint32_t get_handles(const char *buf, int length, RefCountObj * block_ptr = NULL); - int unmarshal(const char *buf, int length, RefCountObj * block_ptr); + uint32_t get_handles(const char *buf, int length, RefCountObj *block_ptr = NULL); + int unmarshal(const char *buf, int length, RefCountObj *block_ptr); CacheArray<vec_info> data; int xcount;
