1.. Licensed to the Apache Software Foundation (ASF) under one
2   or more contributor license agreements.  See the NOTICE file
3   distributed with this work for additional information
4   regarding copyright ownership.  The ASF licenses this file
5   to you under the Apache License, Version 2.0 (the
6   "License"); you may not use this file except in compliance
7   with the License.  You may obtain a copy of the License at
8
9   http://www.apache.org/licenses/LICENSE-2.0
10
11   Unless required by applicable law or agreed to in writing,
12   software distributed under the License is distributed on an
13   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14   KIND, either express or implied.  See the License for the
15   specific language governing permissions and limitations
16   under the License.
17
18==============
19storage.config
20==============
21
22.. configfile:: storage.config
23
24The :file:`storage.config` file (by default, located in
25``/usr/local/etc/trafficserver/``) lists all the files, directories, and/or
26hard disk partitions that make up the Traffic Server cache. After you
27modify the :file:`storage.config` file the new settings will not be effective until Traffic Server is restarted.
28
29Format
30======
31
32The format of the :file:`storage.config` file is a series of lines of the form
33
34   *pathname* *size* [ ``volume=``\ *number* ] [ ``id=``\ *string* ]
35
36where :arg:`pathname` is the name of a partition, directory or file, :arg:`size` is the size of the
37named partition, directory or file (in bytes), and :arg:`volume` is the volume number used in the
38files :file:`volume.config` and :file:`hosting.config`. :arg:`id` is used for seeding the
39:ref:`assignment-table`. You must specify a size for directories; size is optional for files and raw
40partitions. :arg:`volume` and arg:`seed` are optional.
41
42.. note::
43
44   The :arg:`volume` option is independent of the :arg:`seed` option and either can be used with or without the other,
45   and their ordering on the line is irrelevant.
46
47.. note::
48
49   If the :arg:`id` option is used every use must have a unique value for :arg:`string`.
50
51.. note::
52
53   Any change to this files can (and almost always will) invalidate the existing cache in its entirety.
54
55You can use any partition of any size. For best performance:
56
57-  Use raw disk partitions.
58-  For each disk, make all partitions the same size.
59-  For each node, use the same number of partitions on all disks.
60-  Group similar kinds of storage into different volumes. For example
61   split out SSD's or RAM drives into their own volume.
62
63Specify pathnames according to your operating system requirements. See
64the following examples. In the :file:`storage.config` file, a formatted or
65raw disk must be at least 128 MB.
66
67When using raw disk or partitions, you should make sure the :ts:cv:`Traffic
68Server user <proxy.config.admin.user_id>` used by the Traffic Server process
69has read and write privileges on the raw disk device or partition. One good
70practice is to make sure the device file is set with 'g+rw' and the Traffic
71Server user is in the group which owns the device file.  However, some
72operating systems have stronger requirements - see the following examples for
73more information.
74
75As with standard ``records.config`` integers, human readable prefixes are also
76supported. They include
77
78   - ``K`` Kilobytes (1024 bytes)
79   - ``M`` Megabytes (1024^2 or 1,048,576 bytes)
80   - ``G`` Gigabytes (1024^3 or 1,073,741,824 bytes)
81   - ``T`` Terabytes (1024^4 or 1,099,511,627,776 bytes)
82
83.. _assignment-table:
84
85Assignment Table
86----------------
87
88Each storage element defined in :file:`storage.config` is divided in to :term:`stripes <cache stripe>`. The
89assignment table maps from an object URL to a specific stripe. The table is initialized based on a
90pseudo-random process which is seeded by hashing a string for each stripe. This string is composed
91of a base string, an offset (the start of the stripe on the storage element), and the length of the
92stripe. By default the path for the storage is used as the base string. This ensures that each
93stripe has a unique string for the assignment hash. This does make the assignment table very
94sensitive to the path for the storage elements and changing even one can have a cascading effect
95which will effectively clear most of the cache. This can be problem when drives fail and a system
96reboot causes the path names to change.
97
98The :arg:`id` option can be used to create a fixed string that an administrator can use to keep the
99assignment table consistent by maintaining the mapping from physical device to base string even in the presence of hardware changes and failures.
100
101Examples
102========
103
104The following basic example shows 128 MB of cache storage in the
105``/big_dir`` directory::
106
107   /big_dir 134217728
108
109You can use the ``.`` symbol for the current directory. Here is an
110example for 64 MB of cache storage in the current directory::
111
112   . 134217728
113
114As an alternative, using the human readable prefixes, you can express a 64GB
115cache file with::
116
117   /really_big_dir 64G
118
119
120.. note::
121    When using on-filesystem cache disk storage, you can only have one such
122    directory specified. This will be addressed in a future version.
123
124
125Solaris Example
126---------------
127
128The following example is for the Solaris operating system::
129
130   /dev/rdsk/c0t0d0s5
131   /dev/rdsk/c0t0d1s5
132
133.. note:: Size is optional. If not specified, the entire partition is used.
134
135Linux Example
136-------------
137.. note::
138    Rather than refer to disk devices like ``/dev/sda``, ``/dev/sdb``, etc.,
139    modern Linux supports `alternative symlinked names for disk devices
140    <https://wiki.archlinux.org/index.php/persistent_block_device_naming#by-id_and_by-path>`_ in the ``/dev/disk``
141    directory structure. As noted for the :ref:`assignment-table` the path used for the disk can effect
142    the cache if it changes. This can be ameliorated in some cases by using one of the alternate paths
143    in via ``/dev/disk``. Note that if the ``by-id`` or ``by-path`` style is used, replacing a failed drive will cause
144    that path to change because the new drive will have a different physical ID or path. The original hash string can
145    be kept by adding :arg:`id` or :arg:`path` with the original path to the storage line.
146
147    If this is not sufficient then the :arg:`id` or :arg:`path` argument should be used to create a more permanent
148    assignment table. An example would be::
149
150       /dev/sde id=cache.disk.0
151       /dev/sdg id=cache.disk.1
152
153The following example will use an entire raw disk in the Linux operating
154system::
155
156   /dev/disk/by-id/[DiskA_ID]    volume=1
157   /dev/disk/by-path/[DiskB_Path]   volume=2
158
159In order to make sure :program:`traffic_server` will have access to this disk
160you can use :manpage:`udev(7)` to persistently set the right permissions. The
161following rules are targeted for an Ubuntu system, and stored in
162``/etc/udev/rules.d/51-cache-disk.rules``::
163
164   # Assign DiskA and DiskB to the tserver group
165   # make the assignment final, no later changes allowed to the group!
166   SUBSYSTEM=="block", KERNEL=="sd[ef]", GROUP:="tserver"
167
168In order to apply these settings, trigger a reload with :manpage:`udevadm(8)`:::
169
170   udevadm trigger --subsystem-match=block
171
172
173FreeBSD Example
174---------------
175
176Starting with 5.1 FreeBSD dropped support for explicit raw devices. All
177devices on FreeBSD can be accessed raw now.
178
179The following example will use an entire raw disk in the FreeBSD
180operating system::
181
182   /dev/ada1
183   /dev/ada2
184
185In order to make sure :program:`traffic_server` will have access to this disk
186you can use :manpage:`devfs(8)` to persistently set the right permissions. The
187following rules are stored in :manpage:`devfs.conf(5)`::
188
189   # Assign /dev/ada1 and /dev/ada2 to the tserver user
190   own    ada[12]  tserver:tserver
191
192Advanced
193--------
194
195Because relative paths in :file:`storage.config` are relative to the base prefix, when using customized runroot
196it may be necessary to adjust such paths in :file:`storage.config` or adjust ``runroot.yaml`` itself.
197Despite the name, the cachedir value is not used for this file.
198