• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

P_CacheBC.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   Backwards compatibility support for the cache.
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 
00025 #ifndef _P_CACHE_BC_H__
00026 #define _P_CACHE_BC_H__
00027 
00028 namespace cache_bc {
00029 
00030   /* This looks kind of dumb, but I think it's useful. We import external structure
00031      dependencies in to this namespace so we can at least (1) notice them and
00032      (2) change them if the current structure changes.
00033   */
00034 
00035   typedef HTTPHdr HTTPHdr_v21;
00036   typedef HdrHeap HdrHeap_v23;
00037   typedef CryptoHash CryptoHash_v23;
00038   typedef HTTPCacheAlt HTTPCacheAlt_v23;
00039 
00040   /** Cache backwards compatibility structure - the fragment table.
00041       This is copied from @c HTTPCacheAlt in @c HTTP.h.
00042   */
00043   struct HTTPCacheFragmentTable {
00044     /// # of fragment offsets in this alternate.
00045     /// @note This is one less than the number of fragments.
00046     int m_frag_offset_count;
00047     /// Type of offset for a fragment.
00048     typedef uint64_t FragOffset;
00049     /// Table of fragment offsets.
00050     /// @note The offsets are forward looking so that frag[0] is the
00051     /// first byte past the end of fragment 0 which is also the first
00052     /// byte of fragment 1. For this reason there is no fragment offset
00053     /// for the last fragment.
00054     FragOffset *m_frag_offsets;
00055     /// # of fragment offsets built in to object.
00056     static int const N_INTEGRAL_FRAG_OFFSETS = 4;
00057     /// Integral fragment offset table.
00058     FragOffset m_integral_frag_offsets[N_INTEGRAL_FRAG_OFFSETS];
00059   };
00060 
00061   // From before moving the fragment table to the alternate.
00062   struct HTTPCacheAlt_v21
00063   {
00064     uint32_t m_magic;
00065 
00066     int32_t m_writeable;
00067     int32_t m_unmarshal_len;
00068 
00069     int32_t m_id;
00070     int32_t m_rid;
00071 
00072     int32_t m_object_key[4];
00073     int32_t m_object_size[2];
00074 
00075     HTTPHdr_v21 m_request_hdr;
00076     HTTPHdr_v21 m_response_hdr;
00077 
00078     time_t m_request_sent_time;
00079     time_t m_response_received_time;
00080 
00081     RefCountObj *m_ext_buffer;
00082 
00083     // The following methods were added for BC support.
00084     // Checks itself to verify that it is unmarshalled and v21 format.
00085     bool is_unmarshalled_format() const {
00086       return CACHE_ALT_MAGIC_MARSHALED == m_magic && reinterpret_cast<intptr_t>(m_request_hdr.m_heap) == sizeof(*this);
00087     }
00088   };
00089 
00090   /// Really just a namespace, doesn't depend on any of the members.
00091   struct HTTPInfo_v21 {
00092     typedef uint64_t FragOffset;
00093     /// Version upgrade methods
00094     /// @a src , @a dst , and @a n are updated upon return.
00095     /// @a n is the space in @a dst remaining.
00096     /// @return @c false if something went wrong.
00097     static bool copy_and_upgrade_unmarshalled_to_v23(char*& dst, char*& src, size_t& length, int n_frags, FragOffset* frag_offsets);
00098     /// The size of the marshalled data of a marshalled alternate header.
00099     static size_t marshalled_length(void* data);
00100   };
00101 
00102   /// Pre version 24.
00103   struct Doc_v23
00104   {
00105     uint32_t magic;         // DOC_MAGIC
00106     uint32_t len;           // length of this segment (including hlen, flen & sizeof(Doc), unrounded)
00107     uint64_t total_len;     // total length of document
00108     CryptoHash_v23 first_key;    ///< first key in object.
00109     CryptoHash_v23 key; ///< Key for this doc.
00110     uint32_t hlen; ///< Length of this header.
00111     uint32_t doc_type:8;       ///< Doc type - indicates the format of this structure and its content.
00112     uint32_t _flen:24;   ///< Fragment table length.
00113     uint32_t sync_serial;
00114     uint32_t write_serial;
00115     uint32_t pinned;        // pinned until
00116     uint32_t checksum;
00117 
00118     char* hdr();
00119     char* data();
00120     size_t data_len();
00121   };
00122 
00123   static size_t const sizeofDoc_v23 = sizeof(Doc_v23);
00124   char* Doc_v23::data() { return reinterpret_cast<char*>(this) + sizeofDoc_v23 + _flen + hlen; }
00125   size_t Doc_v23::data_len() { return len - sizeofDoc_v23 - hlen; }
00126   char* Doc_v23::hdr() {  return reinterpret_cast<char*>(this) + sizeofDoc_v23; }
00127 
00128 
00129 } // namespace cache_bc
00130 
00131 #endif /* _P_CACHE_BC_H__ */

Generated by  doxygen 1.7.1