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

I_Cache.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
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 #ifndef _I_CACHE_H__
00025 #define _I_CACHE_H__
00026 
00027 #include "libts.h"
00028 #include "I_EventSystem.h"
00029 #include "I_AIO.h"
00030 #include "I_CacheDefs.h"
00031 #include "I_Store.h"
00032 
00033 #define CACHE_MODULE_MAJOR_VERSION 1
00034 #define CACHE_MODULE_MINOR_VERSION 0
00035 #define CACHE_MODULE_VERSION       makeModuleVersion(CACHE_MODULE_MAJOR_VERSION,\
00036                                                    CACHE_MODULE_MINOR_VERSION,\
00037                                                    PUBLIC_MODULE_HEADER)
00038 
00039 #define CACHE_WRITE_OPT_OVERWRITE       0x0001
00040 #define CACHE_WRITE_OPT_CLOSE_COMPLETE  0x0002
00041 #define CACHE_WRITE_OPT_SYNC            (CACHE_WRITE_OPT_CLOSE_COMPLETE | 0x0004)
00042 #define CACHE_WRITE_OPT_OVERWRITE_SYNC  (CACHE_WRITE_OPT_SYNC | CACHE_WRITE_OPT_OVERWRITE)
00043 
00044 #define SCAN_KB_PER_SECOND      8192 // 1TB/8MB = 131072 = 36 HOURS to scan a TB
00045 
00046 #define RAM_CACHE_ALGORITHM_CLFUS        0
00047 #define RAM_CACHE_ALGORITHM_LRU          1
00048 
00049 #define CACHE_COMPRESSION_NONE           0
00050 #define CACHE_COMPRESSION_FASTLZ         1
00051 #define CACHE_COMPRESSION_LIBZ           2
00052 #define CACHE_COMPRESSION_LIBLZMA        3
00053 
00054 struct CacheVC;
00055 struct CacheDisk;
00056 #ifdef HTTP_CACHE
00057 class CacheLookupHttpConfig;
00058 class URL;
00059 class HTTPHdr;
00060 class HTTPInfo;
00061 
00062 typedef HTTPHdr CacheHTTPHdr;
00063 typedef URL CacheURL;
00064 typedef HTTPInfo CacheHTTPInfo;
00065 #endif
00066 
00067 struct CacheProcessor:public Processor
00068 {
00069   CacheProcessor()
00070     : min_stripe_version(CACHE_DB_MAJOR_VERSION, CACHE_DB_MINOR_VERSION)
00071     , max_stripe_version(CACHE_DB_MAJOR_VERSION, CACHE_DB_MINOR_VERSION)
00072     , cb_after_init(0)
00073   {}
00074 
00075   virtual int start(int n_cache_threads = 0, size_t stacksize = DEFAULT_STACKSIZE);
00076   virtual int start_internal(int flags = 0);
00077   void stop();
00078 
00079   int dir_check(bool fix);
00080   int db_check(bool fix);
00081 
00082   inkcoreapi Action *lookup(Continuation *cont, CacheKey *key, bool cluster_cache_local,
00083                             bool local_only = false,
00084                             CacheFragType frag_type = CACHE_FRAG_TYPE_NONE, char *hostname = 0, int host_len = 0);
00085   inkcoreapi Action *open_read(Continuation *cont, CacheKey *key, bool cluster_cache_local,
00086                                CacheFragType frag_type = CACHE_FRAG_TYPE_NONE, char *hostname = 0, int host_len = 0);
00087   Action *open_read_buffer(Continuation *cont, MIOBuffer *buf, CacheKey *key,
00088                            CacheFragType frag_type = CACHE_FRAG_TYPE_NONE, char *hostname = 0, int host_len = 0);
00089 
00090   inkcoreapi Action *open_write(Continuation *cont,
00091                                 CacheKey *key,
00092                                 bool cluster_cache_local,
00093                                 CacheFragType frag_type = CACHE_FRAG_TYPE_NONE,
00094                                 int expected_size = CACHE_EXPECTED_SIZE,
00095                                 int options = 0,
00096                                 time_t pin_in_cache = (time_t) 0,
00097                                 char *hostname = 0, int host_len = 0);
00098   Action *open_write_buffer(Continuation *cont, MIOBuffer *buf,
00099                             CacheKey *key,
00100                             CacheFragType frag_type = CACHE_FRAG_TYPE_NONE,
00101                             int options = 0,
00102                             time_t pin_in_cache = (time_t) 0,
00103                             char *hostname = 0, int host_len = 0);
00104   inkcoreapi Action *remove(Continuation *cont, CacheKey *key,
00105                             bool cluster_cache_local,
00106                             CacheFragType frag_type = CACHE_FRAG_TYPE_NONE,
00107                             bool rm_user_agents = true, bool rm_link = false,
00108                             char *hostname = 0, int host_len = 0);
00109   Action *scan(Continuation *cont, char *hostname = 0, int host_len = 0, int KB_per_second = SCAN_KB_PER_SECOND);
00110 #ifdef HTTP_CACHE
00111   Action *lookup(Continuation *cont, URL *url, bool cluster_cache_local, bool local_only = false,
00112                  CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
00113   inkcoreapi Action *open_read(Continuation *cont, URL *url,
00114                                bool cluster_cache_local,
00115                                CacheHTTPHdr *request,
00116                                CacheLookupHttpConfig *params,
00117                                time_t pin_in_cache = (time_t) 0, CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
00118   Action *open_read_buffer(Continuation *cont, MIOBuffer *buf, URL *url,
00119                            CacheHTTPHdr *request,
00120                            CacheLookupHttpConfig *params, CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
00121   Action *open_write(Continuation *cont, int expected_size, URL *url, bool cluster_cache_local,
00122                      CacheHTTPHdr *request, CacheHTTPInfo *old_info,
00123                      time_t pin_in_cache = (time_t) 0, CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
00124   Action *open_write_buffer(Continuation *cont, MIOBuffer *buf, URL *url,
00125                             CacheHTTPHdr *request, CacheHTTPHdr *response,
00126                             CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
00127   Action *remove(Continuation *cont, URL *url, bool cluster_cache_local, CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP);
00128 
00129   Action *open_read_internal(int, Continuation *, MIOBuffer *, CacheURL *,
00130                              CacheHTTPHdr *, CacheLookupHttpConfig *,
00131                              CacheKey *, time_t, CacheFragType type, char *hostname, int host_len);
00132 #endif
00133   Action *link(Continuation *cont, CacheKey *from, CacheKey *to, bool cluster_cache_local,
00134                CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP, char *hostname = 0, int host_len = 0);
00135 
00136   Action *deref(Continuation *cont, CacheKey *key, bool cluster_cache_local,
00137                 CacheFragType frag_type = CACHE_FRAG_TYPE_HTTP, char *hostname = 0, int host_len = 0);
00138 
00139   /** Mark physical disk/device/file as offline.
00140       All stripes for this device are disabled.
00141 
00142       @return @c true if there are any storage devices remaining online, @c false if not.
00143 
00144       @note This is what is called if a disk is disabled due to I/O errors.
00145   */
00146   bool mark_storage_offline(CacheDisk* d);
00147 
00148   /** Find the storage for a @a path.
00149       If @a len is 0 then @a path is presumed null terminated.
00150       @return @c NULL if the path does not match any defined storage.
00151    */
00152   CacheDisk* find_by_path(char const* path, int len = 0);
00153 
00154   /** Check if there are any online storage devices.
00155       If this returns @c false then the cache should be disabled as there is no storage available.
00156   */
00157   bool has_online_storage() const;
00158 
00159   static int IsCacheEnabled();
00160 
00161   static bool IsCacheReady(CacheFragType type);
00162 
00163   /// Type for callback function.
00164   typedef void (*CALLBACK_FUNC)();
00165   /** Lifecycle callback.
00166 
00167       The function @a cb is called after cache initialization has
00168       finished and the cache is ready or has failed.
00169 
00170       @internal If we need more lifecycle callbacks, this should be
00171       generalized ala the standard hooks style, with a type enum used
00172       to specific the callback type and passed to the callback
00173       function.
00174   */
00175   void set_after_init_callback(CALLBACK_FUNC cb);
00176 
00177   // private members
00178   void diskInitialized();
00179 
00180   void cacheInitialized();
00181 
00182   static volatile uint32_t cache_ready;
00183   static volatile int initialized;
00184   static volatile int start_done;
00185   static int clear;
00186   static int fix;
00187   static int start_internal_flags;
00188   static int auto_clear_flag;
00189   
00190   VersionNumber min_stripe_version;
00191   VersionNumber max_stripe_version;
00192 
00193   CALLBACK_FUNC cb_after_init;
00194 };
00195 
00196 inline void
00197 CacheProcessor::set_after_init_callback(CALLBACK_FUNC cb)
00198 {
00199   cb_after_init = cb;
00200 }
00201 
00202 struct CacheVConnection:public VConnection
00203 {
00204   VIO *do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) = 0;
00205   virtual VIO *do_io_pread(Continuation *c, int64_t nbytes, MIOBuffer *buf, int64_t offset) = 0;
00206   VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner = false) = 0;
00207   void do_io_close(int lerrno = -1) = 0;
00208   void reenable(VIO *avio) = 0;
00209   void reenable_re(VIO *avio) = 0;
00210   void do_io_shutdown(ShutdownHowTo_t howto)
00211   {
00212     (void) howto;
00213     ink_assert(!"CacheVConnection::do_io_shutdown unsupported");
00214   }
00215 
00216   virtual int get_header(void **ptr, int *len) = 0;
00217   virtual int set_header(void *ptr, int len) = 0;
00218   virtual int get_single_data(void **ptr, int *len) = 0;
00219 
00220 #ifdef HTTP_CACHE
00221   virtual void set_http_info(CacheHTTPInfo *info) = 0;
00222   virtual void get_http_info(CacheHTTPInfo **info) = 0;
00223 #endif
00224 
00225   virtual bool is_ram_cache_hit() const = 0;
00226   virtual bool set_disk_io_priority(int priority) = 0;
00227   virtual int get_disk_io_priority() = 0;
00228   virtual bool set_pin_in_cache(time_t t) = 0;
00229   virtual time_t get_pin_in_cache() = 0;
00230   virtual int64_t get_object_size() = 0;
00231   
00232   /** Test if the VC can support pread.
00233       @return @c true if @c do_io_pread will work, @c false if not.
00234   */
00235   virtual bool is_pread_capable() = 0;
00236 
00237   CacheVConnection();
00238 };
00239 
00240 void ink_cache_init(ModuleVersion version);
00241 extern inkcoreapi CacheProcessor cacheProcessor;
00242 extern Continuation *cacheRegexDeleteCont;
00243 
00244 #endif /* _I_CACHE_H__ */

Generated by  doxygen 1.7.1