You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

610 lines
19 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>storage - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package storage</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "github.com/syndtr/goleveldb/leveldb/storage"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. </dl>
  58. </div>
  59. <!-- The package's Name is printed as title by the top-level template -->
  60. <div id="pkg-overview" class="toggleVisible">
  61. <div class="collapsed">
  62. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  63. </div>
  64. <div class="expanded">
  65. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  66. <p>
  67. Package storage provides storage abstraction for LevelDB.
  68. </p>
  69. </div>
  70. </div>
  71. <div id="pkg-index" class="toggleVisible">
  72. <div class="collapsed">
  73. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  74. </div>
  75. <div class="expanded">
  76. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  77. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  78. <div id="manual-nav">
  79. <dl>
  80. <dd><a href="index.html#pkg-variables">Variables</a></dd>
  81. <dd><a href="index.html#FileDescOk">func FileDescOk(fd FileDesc) bool</a></dd>
  82. <dd><a href="index.html#ErrCorrupted">type ErrCorrupted</a></dd>
  83. <dd>&nbsp; &nbsp; <a href="index.html#ErrCorrupted.Error">func (e *ErrCorrupted) Error() string</a></dd>
  84. <dd><a href="index.html#FileDesc">type FileDesc</a></dd>
  85. <dd>&nbsp; &nbsp; <a href="index.html#FileDesc.String">func (fd FileDesc) String() string</a></dd>
  86. <dd>&nbsp; &nbsp; <a href="index.html#FileDesc.Zero">func (fd FileDesc) Zero() bool</a></dd>
  87. <dd><a href="index.html#FileType">type FileType</a></dd>
  88. <dd>&nbsp; &nbsp; <a href="index.html#FileType.String">func (t FileType) String() string</a></dd>
  89. <dd><a href="index.html#Locker">type Locker</a></dd>
  90. <dd><a href="index.html#Reader">type Reader</a></dd>
  91. <dd><a href="index.html#Storage">type Storage</a></dd>
  92. <dd>&nbsp; &nbsp; <a href="index.html#NewMemStorage">func NewMemStorage() Storage</a></dd>
  93. <dd>&nbsp; &nbsp; <a href="index.html#OpenFile">func OpenFile(path string, readOnly bool) (Storage, error)</a></dd>
  94. <dd><a href="index.html#Syncer">type Syncer</a></dd>
  95. <dd><a href="index.html#Writer">type Writer</a></dd>
  96. </dl>
  97. </div><!-- #manual-nav -->
  98. <h4>Package files</h4>
  99. <p>
  100. <span style="font-size:90%">
  101. <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage.go">file_storage.go</a>
  102. <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage_unix.go">file_storage_unix.go</a>
  103. <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/mem_storage.go">mem_storage.go</a>
  104. <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go">storage.go</a>
  105. </span>
  106. </p>
  107. </div><!-- .expanded -->
  108. </div><!-- #pkg-index -->
  109. <div id="pkg-callgraph" class="toggle" style="display: none">
  110. <div class="collapsed">
  111. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  112. </div> <!-- .expanded -->
  113. <div class="expanded">
  114. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  115. <p>
  116. In the call graph viewer below, each node
  117. is a function belonging to this package
  118. and its children are the functions it
  119. calls&mdash;perhaps dynamically.
  120. </p>
  121. <p>
  122. The root nodes are the entry points of the
  123. package: functions that may be called from
  124. outside the package.
  125. There may be non-exported or anonymous
  126. functions among them if they are called
  127. dynamically from another package.
  128. </p>
  129. <p>
  130. Click a node to visit that function's source code.
  131. From there you can visit its callers by
  132. clicking its declaring <code>func</code>
  133. token.
  134. </p>
  135. <p>
  136. Functions may be omitted if they were
  137. determined to be unreachable in the
  138. particular programs or tests that were
  139. analyzed.
  140. </p>
  141. <!-- Zero means show all package entry points. -->
  142. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  143. </div>
  144. </div> <!-- #pkg-callgraph -->
  145. <h2 id="pkg-variables">Variables</h2>
  146. <pre>var (
  147. <span id="ErrInvalidFile">ErrInvalidFile</span> = <a href="../../../../../errors/index.html">errors</a>.<a href="../../../../../errors/index.html#New">New</a>(&#34;leveldb/storage: invalid file for argument&#34;)
  148. <span id="ErrLocked">ErrLocked</span> = <a href="../../../../../errors/index.html">errors</a>.<a href="../../../../../errors/index.html#New">New</a>(&#34;leveldb/storage: already locked&#34;)
  149. <span id="ErrClosed">ErrClosed</span> = <a href="../../../../../errors/index.html">errors</a>.<a href="../../../../../errors/index.html#New">New</a>(&#34;leveldb/storage: closed&#34;)
  150. )</pre>
  151. <p>
  152. Common error.
  153. </p>
  154. <h2 id="FileDescOk">func <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=2521:2554#L108">FileDescOk</a></h2>
  155. <pre>func FileDescOk(fd <a href="index.html#FileDesc">FileDesc</a>) <a href="../../../../../builtin/index.html#bool">bool</a></pre>
  156. <p>
  157. FileDescOk returns true if fd is a valid &#39;file descriptor&#39;.
  158. </p>
  159. <h2 id="ErrCorrupted">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=1163:1216#L43">ErrCorrupted</a></h2>
  160. <pre>type ErrCorrupted struct {
  161. Fd <a href="index.html#FileDesc">FileDesc</a>
  162. Err <a href="../../../../../builtin/index.html#error">error</a>
  163. }</pre>
  164. <p>
  165. ErrCorrupted is the type that wraps errors that indicate corruption of
  166. a file. Package storage has its own type instead of using
  167. errors.ErrCorrupted to prevent circular import.
  168. </p>
  169. <h3 id="ErrCorrupted.Error">func (*ErrCorrupted) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=1218:1255#L48">Error</a></h3>
  170. <pre>func (e *<a href="index.html#ErrCorrupted">ErrCorrupted</a>) Error() <a href="../../../../../builtin/index.html#string">string</a></pre>
  171. <h2 id="FileDesc">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=1938:1989#L82">FileDesc</a></h2>
  172. <pre>type FileDesc struct {
  173. Type <a href="index.html#FileType">FileType</a>
  174. Num <a href="../../../../../builtin/index.html#int64">int64</a>
  175. }</pre>
  176. <p>
  177. FileDesc is a &#39;file descriptor&#39;.
  178. </p>
  179. <h3 id="FileDesc.String">func (FileDesc) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=1991:2025#L87">String</a></h3>
  180. <pre>func (fd <a href="index.html#FileDesc">FileDesc</a>) String() <a href="../../../../../builtin/index.html#string">string</a></pre>
  181. <h3 id="FileDesc.Zero">func (FileDesc) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=2395:2425#L103">Zero</a></h3>
  182. <pre>func (fd <a href="index.html#FileDesc">FileDesc</a>) Zero() <a href="../../../../../builtin/index.html#bool">bool</a></pre>
  183. <p>
  184. Zero returns true if fd == (FileDesc{}).
  185. </p>
  186. <h2 id="FileType">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=343:360#L7">FileType</a></h2>
  187. <pre>type FileType <a href="../../../../../builtin/index.html#int">int</a></pre>
  188. <p>
  189. FileType represent a file type.
  190. </p>
  191. <pre>const (
  192. <span id="TypeManifest">TypeManifest</span> <a href="index.html#FileType">FileType</a> = 1 &lt;&lt; <a href="../../../../../builtin/index.html#iota">iota</a>
  193. <span id="TypeJournal">TypeJournal</span>
  194. <span id="TypeTable">TypeTable</span>
  195. <span id="TypeTemp">TypeTemp</span>
  196. <span id="TypeAll">TypeAll</span> = <a href="index.html#TypeManifest">TypeManifest</a> | <a href="index.html#TypeJournal">TypeJournal</a> | <a href="index.html#TypeTable">TypeTable</a> | <a href="index.html#TypeTemp">TypeTemp</a>
  197. )</pre>
  198. <p>
  199. File types.
  200. </p>
  201. <h3 id="FileType.String">func (FileType) <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=519:552#L19">String</a></h3>
  202. <pre>func (t <a href="index.html#FileType">FileType</a>) String() <a href="../../../../../builtin/index.html#string">string</a></pre>
  203. <h2 id="Locker">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=1865:1900#L77">Locker</a></h2>
  204. <pre>type Locker interface {
  205. Unlock()
  206. }</pre>
  207. <p>
  208. Locker is the interface that wraps Unlock method.
  209. </p>
  210. <h2 id="Reader">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=1612:1676#L63">Reader</a></h2>
  211. <pre>type Reader interface {
  212. <a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#ReadSeeker">ReadSeeker</a>
  213. <a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#ReaderAt">ReaderAt</a>
  214. <a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#Closer">Closer</a>
  215. }</pre>
  216. <p>
  217. Reader is the interface that groups the basic Read, Seek, ReadAt and Close
  218. methods.
  219. </p>
  220. <h2 id="Storage">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=2777:4681#L121">Storage</a></h2>
  221. <pre>type Storage interface {
  222. <span class="comment">// Lock locks the storage. Any subsequent attempt to call Lock will fail</span>
  223. <span class="comment">// until the last lock released.</span>
  224. <span class="comment">// Caller should call Unlock method after use.</span>
  225. Lock() (<a href="index.html#Locker">Locker</a>, <a href="../../../../../builtin/index.html#error">error</a>)
  226. <span class="comment">// Log logs a string. This is used for logging.</span>
  227. <span class="comment">// An implementation may write to a file, stdout or simply do nothing.</span>
  228. Log(str <a href="../../../../../builtin/index.html#string">string</a>)
  229. <span class="comment">// SetMeta store &#39;file descriptor&#39; that can later be acquired using GetMeta</span>
  230. <span class="comment">// method. The &#39;file descriptor&#39; should point to a valid file.</span>
  231. <span class="comment">// SetMeta should be implemented in such way that changes should happen</span>
  232. <span class="comment">// atomically.</span>
  233. SetMeta(fd <a href="index.html#FileDesc">FileDesc</a>) <a href="../../../../../builtin/index.html#error">error</a>
  234. <span class="comment">// GetMeta returns &#39;file descriptor&#39; stored in meta. The &#39;file descriptor&#39;</span>
  235. <span class="comment">// can be updated using SetMeta method.</span>
  236. <span class="comment">// Returns os.ErrNotExist if meta doesn&#39;t store any &#39;file descriptor&#39;, or</span>
  237. <span class="comment">// &#39;file descriptor&#39; point to nonexistent file.</span>
  238. GetMeta() (<a href="index.html#FileDesc">FileDesc</a>, <a href="../../../../../builtin/index.html#error">error</a>)
  239. <span class="comment">// List returns file descriptors that match the given file types.</span>
  240. <span class="comment">// The file types may be OR&#39;ed together.</span>
  241. List(ft <a href="index.html#FileType">FileType</a>) ([]<a href="index.html#FileDesc">FileDesc</a>, <a href="../../../../../builtin/index.html#error">error</a>)
  242. <span class="comment">// Open opens file with the given &#39;file descriptor&#39; read-only.</span>
  243. <span class="comment">// Returns os.ErrNotExist error if the file does not exist.</span>
  244. <span class="comment">// Returns ErrClosed if the underlying storage is closed.</span>
  245. Open(fd <a href="index.html#FileDesc">FileDesc</a>) (<a href="index.html#Reader">Reader</a>, <a href="../../../../../builtin/index.html#error">error</a>)
  246. <span class="comment">// Create creates file with the given &#39;file descriptor&#39;, truncate if already</span>
  247. <span class="comment">// exist and opens write-only.</span>
  248. <span class="comment">// Returns ErrClosed if the underlying storage is closed.</span>
  249. Create(fd <a href="index.html#FileDesc">FileDesc</a>) (<a href="index.html#Writer">Writer</a>, <a href="../../../../../builtin/index.html#error">error</a>)
  250. <span class="comment">// Remove removes file with the given &#39;file descriptor&#39;.</span>
  251. <span class="comment">// Returns ErrClosed if the underlying storage is closed.</span>
  252. Remove(fd <a href="index.html#FileDesc">FileDesc</a>) <a href="../../../../../builtin/index.html#error">error</a>
  253. <span class="comment">// Rename renames file from oldfd to newfd.</span>
  254. <span class="comment">// Returns ErrClosed if the underlying storage is closed.</span>
  255. Rename(oldfd, newfd <a href="index.html#FileDesc">FileDesc</a>) <a href="../../../../../builtin/index.html#error">error</a>
  256. <span class="comment">// Close closes the storage.</span>
  257. <span class="comment">// It is valid to call Close multiple times. Other methods should not be</span>
  258. <span class="comment">// called after the storage has been closed.</span>
  259. Close() <a href="../../../../../builtin/index.html#error">error</a>
  260. }</pre>
  261. <p>
  262. Storage is the storage. A storage instance must be safe for concurrent use.
  263. </p>
  264. <h3 id="NewMemStorage">func <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/mem_storage.go?s=683:711#L30">NewMemStorage</a></h3>
  265. <pre>func NewMemStorage() <a href="index.html#Storage">Storage</a></pre>
  266. <p>
  267. NewMemStorage returns a new memory-backed storage implementation.
  268. </p>
  269. <h3 id="OpenFile">func <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage.go?s=1325:1383#L58">OpenFile</a></h3>
  270. <pre>func OpenFile(path <a href="../../../../../builtin/index.html#string">string</a>, readOnly <a href="../../../../../builtin/index.html#bool">bool</a>) (<a href="index.html#Storage">Storage</a>, <a href="../../../../../builtin/index.html#error">error</a>)</pre>
  271. <p>
  272. OpenFile returns a new filesytem-backed storage implementation with the given
  273. path. This also acquire a file lock, so any subsequent attempt to open the
  274. same path will fail.
  275. </p>
  276. <p>
  277. The storage must be closed after use, by calling Close method.
  278. </p>
  279. <h2 id="Syncer">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=1412:1520#L56">Syncer</a></h2>
  280. <pre>type Syncer interface {
  281. <span class="comment">// Sync commits the current contents of the file to stable storage.</span>
  282. Sync() <a href="../../../../../builtin/index.html#error">error</a>
  283. }</pre>
  284. <p>
  285. Syncer is the interface that wraps basic Sync method.
  286. </p>
  287. <h2 id="Writer">type <a href="http://localhost:6060/src/github.com/syndtr/goleveldb/leveldb/storage/storage.go?s=1761:1810#L71">Writer</a></h2>
  288. <pre>type Writer interface {
  289. <a href="../../../../../io/index.html">io</a>.<a href="../../../../../io/index.html#WriteCloser">WriteCloser</a>
  290. <a href="index.html#Syncer">Syncer</a>
  291. }</pre>
  292. <p>
  293. Writer is the interface that groups the basic Write, Sync and Close
  294. methods.
  295. </p>
  296. <div id="footer">
  297. Build version go1.6.<br>
  298. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  299. the content of this page is licensed under the
  300. Creative Commons Attribution 3.0 License,
  301. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  302. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  303. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  304. </div>
  305. </div><!-- .container -->
  306. </div><!-- #page -->
  307. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  308. <script type="text/javascript" src="../../../../../../lib/godoc/jquery.js"></script>
  309. <script type="text/javascript" src="../../../../../../lib/godoc/jquery.treeview.js"></script>
  310. <script type="text/javascript" src="../../../../../../lib/godoc/jquery.treeview.edit.js"></script>
  311. <script type="text/javascript" src="../../../../../../lib/godoc/godocs.js"></script>
  312. </body>
  313. </html>