Debian Codegraph @

lmdb/example_test.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 package lmdb_test
2
3 import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 "log"
8 "os"
9 "runtime"
10 "time"
11
12 "github.com/bmatsuo/lmdb-go/lmdb"
13 )
14
15 // These values shouldn't actually be assigned to. The are used as stand-ins
16 // for tests which do not act as tests.
17 var EnvEx *lmdb.Env
18 var DBIEx lmdb.DBI
19
20 // These values can only be used is code-only examples (no test output).
21 var env *lmdb.Env
22 var txn *lmdb.Txn
23 var dbi lmdb.DBI
24 var dbname string
25 var err error
26 var stop chan struct{}
27
28 // These values can be used as no-op placeholders in examples.
29 func doUpdate(txn *lmdb.Txn) error { return nil }
30 func doUpdate1(txn *lmdb.Txn) error { return nil }
31 func doUpdate2(txn *lmdb.Txn) error { return nil }
32 func doView(txn *lmdb.Txn) error { return nil }
33
34 // This example demonstrates a complete workflow for a simple application
35 // working with LMDB. First, an Env is configured and mapped to memory. Once
36 // mapped, database handles are opened and normal database operations may
37 // begin.
38 func Example() {
39 // Create an environment and make sure it is eventually closed.
40 env, err := lmdb.NewEnv()
41 if err != nil {
42 // ...
43 }
44 defer env.Close()
45
46 // Configure and open the environment. Most configuration must be done
47 // before opening the environment. The go documentation for each method
48 // should indicate if it must be called before calling env.Open()
49 err = env.SetMaxDBs(1)
50 if err != nil {
51 // ..
52 }
53 err = env.SetMapSize(1 << 30)
54 if err != nil {
55 // ..
56 }
57 err = env.Open("/path/to/db/", 0, 0644)
58 if err != nil {
59 // ..
60 }
61
62 // In any real application it is important to check for readers that were
63 // never closed by their owning process, and for which the owning process
64 // has exited. See the documentation on transactions for more information.
65 staleReaders, err := env.ReaderCheck()
66 if err != nil {
67 // ...
68 }
69 if staleReaders > 0 {
70 log.Printf("cleared %d reader slots from dead processes", staleReaders)
71 }
72
73 // Open a database handle that will be used for the entire lifetime of this
74 // application. Because the database may not have existed before, and the
75 // database may need to be created, we need to get the database handle in
76 // an update transacation.
77 var dbi lmdb.DBI
78 err = env.Update(func(txn *lmdb.Txn) (err error) {
79 dbi, err = txn.CreateDBI("example")
80 return err
81 })
82 if err != nil {
83 // ...
84 }
85
86 // The database referenced by our DBI handle is now ready for the
87 // application to use. Here the application just opens a readonly
88 // transaction and reads the data stored in the "hello" key and prints its
89 // value to the application's standard output.
90 err = env.View(func(txn *lmdb.Txn) (err error) {
91 v, err := txn.Get(dbi, []byte("hello"))
92 if err != nil {
93 return err
94 }
95 fmt.Println(string(v))
96 return nil
97 })
98 if err != nil {
99 // ...
100 }
101 }
102
103 // This example demonstrates the simplest (and most naive) way to issue
104 // database updates from a goroutine for which it cannot be known ahead of time
105 // whether runtime.LockOSThread has been called.
106 func Example_threads() {
107 // Create a function that wraps env.Update and sends the resulting error
108 // over a channel. Because env.Update is called our update function will
109 // call runtime.LockOSThread to safely issue the update operation.
110 update := func(res chan<- error, op lmdb.TxnOp) {
111 res <- env.Update(op)
112 }
113
114 // ...
115
116 // Now, in goroutine where we cannot determine if we are locked to a
117 // thread, we can create a new goroutine to process the update(s) we want.
118 res := make(chan error)
119 go update(res, func(txn *lmdb.Txn) (err error) {
120 return txn.Put(dbi, []byte("thisUpdate"), []byte("isSafe"), 0)
121 })
122 err = <-res
123 if err != nil {
124 panic(err)
125 }
126 }
127
128 // This example demonstrates a more sophisticated way to issue database updates
129 // from a goroutine for which it cannot be known ahead of time whether
130 // runtime.LockOSThread has been called.
131 func Example_worker() {
132 // Wrap operations in a struct that can be passed over a channel to a
133 // worker goroutine.
134 type lmdbop struct {
135 op lmdb.TxnOp
136 res chan<- error
137 }
138 worker := make(chan *lmdbop)
139 update := func(op lmdb.TxnOp) error {
140 res := make(chan error)
141 worker <- &lmdbop{op, res}
142 return <-res
143 }
144
145 // Start issuing update operations in a goroutine in which we know
146 // runtime.LockOSThread can be called and we can safely issue transactions.
147 go func() {
148 runtime.LockOSThread()
149 defer runtime.LockOSThread()
150
151 // Perform each operation as we get to it. Because this goroutine is
152 // already locked to a thread, env.UpdateLocked is called to avoid
153 // premature unlocking of the goroutine from its thread.
154 for op := range worker {
155 op.res <- env.UpdateLocked(op.op)
156 }
157 }()
158
159 // ...
160
161 // In another goroutine, where we cannot determine if we are locked to a
162 // thread already.
163 err = update(func(txn *lmdb.Txn) (err error) {
164 // This function will execute safely in the worker goroutine, which is
165 // locked to its thread.
166 return txn.Put(dbi, []byte("thisUpdate"), []byte("isSafe"), 0)
167 })
168 }
169
170 // This example demonstrates how an application typically uses Env.SetMapSize.
171 // The call to Env.SetMapSize() is made before calling env.Open(). Any calls
172 // after calling Env.Open() must take special care to synchronize with other
173 // goroutines.
174 func ExampleEnv_SetMapSize() {
175 env, err := lmdb.NewEnv()
176 if err != nil {
177 // ...
178 }
179
180 // set the memory map size (maximum database size) to 1GB.
181 err = env.SetMapSize(1 << 30)
182 if err != nil {
183 // ...
184 }
185
186 err = env.Open("mydb", 0, 0644)
187 if err != nil {
188 // ...
189 }
190 // ...
191 }
192
193 // This example demonstrates how to handle a MapResized error, encountered
194 // after another process has called mdb_env_set_mapsize (Env.SetMapSize).
195 // Applications which don't expect another process to resize the mmap don't
196 // need to check for the MapResized error.
197 //
198 // The example is simplified for clarity. Many real applications will need to
199 // synchronize calls to Env.SetMapSize using something like a sync.RWMutex to
200 // ensure there are no active readonly transactions (those opened successfully
201 // before MapResized was encountered).
202 func ExampleEnv_SetMapSize_mapResized() {
203 retry:
204 err := env.Update(doUpdate)
205 if lmdb.IsMapResized(err) {
206 // If concurrent read transactions are possible then a sync.RWMutex
207 // must be used here to ensure they all terminate before calling
208 // env.SetMapSize().
209 err = env.SetMapSize(0)
210 if err != nil {
211 panic(err)
212 }
213
214 // retry the update. a goto is not necessary but it simplifies error
215 // handling with minimal overhead.
216 goto retry
217 } else if err != nil {
218 // ...
219 }
220 // ...
221 }
222
223 func backupFailed(err error) {}
224
225 // This example uses env.Copy to periodically create atomic backups of an
226 // environment. A real implementation would need to solve problems with
227 // failures, remote persistence, purging old backups, etc. But the core loop
228 // would have the same form.
229 func ExampleEnv_Copy() {
230 go func(backup <-chan time.Time) {
231 for {
232 select {
233 case <-backup:
234 now := time.Now().UTC()
235 backup := fmt.Sprintf("backup-%s", now.Format(time.RFC3339))
236 os.Mkdir(backup, 0755)
237 err = env.Copy(backup)
238 if err != nil {
239 // ...
240 continue
241 }
242 case <-stop:
243 return
244 }
245 }
246 }(time.Tick(time.Hour))
247 }
248
249 // This example shows the basic use of Env.Update, the primary method lmdb-go
250 // provides for to store data in an Env.
251 func ExampleEnv_Update() {
252 // It is not safe to call runtime.LockOSThread here because Env.Update
253 // would later cause premature unlocking of the goroutine. If an
254 // application requires that goroutines be locked to threads before
255 // starting an an update on the Env then you must use Env.UpdateLocked
256 // instead of Env.Update.
257
258 err = env.Update(func(txn *lmdb.Txn) (err error) {
259 // Write several keys to the database within one transaction. If
260 // either write fails and this function returns an error then readers
261 // in other transactions will not see either value because Env.Update
262 // aborts the transaction if an error is returned.
263
264 err = txn.Put(dbi, []byte("x"), []byte("hello"), 0)
265 if err != nil {
266 return err
267 }
268 err = txn.Put(dbi, []byte("y"), []byte("goodbye"), 0)
269 if err != nil {
270 return err
271 }
272 return nil
273 })
274 if err != nil {
275 panic(err)
276 }
277 }
278
279 // In this example, another C library requires the application to lock a
280 // goroutine to its thread. When writing to the Env this goroutine must use
281 // the method Env.UpdateLocked to prevent premature unlocking of the goroutine.
282 //
283 // Note that there is no way for a goroutine to determine if it is locked to a
284 // thread failure to call Env.UpdateLocked in a scenario like this can lead to
285 // unspecified and hard to debug failure modes for your application.
286 func ExampleEnv_UpdateLocked() {
287 runtime.LockOSThread()
288 defer runtime.UnlockOSThread()
289
290 // ... Do something that requires the goroutine be locked to its thread.
291
292 // Create a transaction that will not interfere with thread locking and
293 // issue some writes with it.
294 err = env.UpdateLocked(func(txn *lmdb.Txn) (err error) {
295 err = txn.Put(dbi, []byte("x"), []byte("hello"), 0)
296 if err != nil {
297 return err
298 }
299 err = txn.Put(dbi, []byte("y"), []byte("goodbye"), 0)
300 if err != nil {
301 return err
302 }
303 return nil
304 })
305 if err != nil {
306 panic(err)
307 }
308
309 // ... Do something requiring the goroutine still be locked to its thread.
310 }
311
312 // This example shows the general workflow of LMDB. An environment is created
313 // and configured before being opened. After the environment is opened its
314 // databases are created and their handles are saved for use in future
315 // transactions.
316 func ExampleEnv() {
317 // open the LMDB environment and configure common options like its size and
318 // maximum number of databases.
319 env, err := lmdb.NewEnv()
320 if err != nil {
321 // ...
322 }
323 err = env.SetMapSize(100 * 1024 * 1024) // 100MB
324 if err != nil {
325 // ...
326 }
327 err = env.SetMaxDBs(1)
328 if err != nil {
329 // ...
330 }
331
332 // open the environment only after the it has been configured. some
333 // settings may only be called before the environment is opened where
334 // others may have caveats.
335 err = env.Open("mydb/", 0, 0664)
336 if err != nil {
337 // ...
338 }
339 defer env.Close()
340
341 err = env.Update(func(txn *lmdb.Txn) (err error) {
342 // open a database, creating it if necessary. the database is stored
343 // outside the transaction via closure and can be use after the
344 // transaction is committed.
•345 _, err = txn.OpenDBI("exampledb", lmdb.Create)
346 if err != nil {
347 return err
348 }
349
350 // commit the transaction, writing an entry for the newly created
351 // database if it was just created and allowing the dbi to be used in
352 // future transactions.
353 return nil
354 })
355 if err != nil {
356 panic(err)
357 }
358 }
359
360 // This example shows the basic operations used when creating and working with
361 // Txn types.
362 func ExampleTxn() {
363 // open a database.
364 var dbi lmdb.DBI
365 err := env.Update(func(txn *lmdb.Txn) (err error) {
366 dbi, err = txn.OpenDBI("exampledb", lmdb.Create)
367 // the transaction will be commited if the database was successfully
368 // opened/created.
369 return err
370 })
371 if err != nil {
372 // ...
373 }
374
375 err = env.Update(func(txn *lmdb.Txn) (err error) {
376 return txn.Put(dbi, []byte("k"), []byte("v"), 0)
377 })
378 if err != nil {
379 // ...
380 }
381
382 err = env.View(func(txn *lmdb.Txn) (err error) {
383 v, err := txn.Get(dbi, []byte("k"))
384 if err != nil {
385 return err
386 }
387 fmt.Println(string(v))
388 return nil
389 })
390 if err != nil {
391 // ...
392 }
393 }
394
395 // This example demonstrates how to iterate a database opened with the DupSort
396 // flag and get the number of values present for each distinct key.
397 func ExampleCursor_Count() {
398 err = env.Update(func(txn *lmdb.Txn) (err error) {
399 cur, err := txn.OpenCursor(dbi)
400 if err != nil {
401 return err
402 }
403 defer cur.Close()
404
405 for {
406 k, _, err := cur.Get(nil, nil, lmdb.NextNoDup)
407 if lmdb.IsNotFound(err) {
408 return nil
409 }
410 if err != nil {
411 return err
412 }
413
414 numdup, err := cur.Count()
415 if err != nil {
416 return err
417 }
418 fmt.Printf("%d values for key %q", numdup, k)
419 }
420 })
421 }
422
423 // This simple example shows how to iterate a database. The Next flag may be
424 // used without an initial call passing the First flag.
425 func ExampleCursor_Get() {
426 err = env.View(func(txn *lmdb.Txn) (err error) {
427 cur, err := txn.OpenCursor(dbi)
428 if err != nil {
429 return err
430 }
431 defer cur.Close()
432
433 for {
434 k, v, err := cur.Get(nil, nil, lmdb.Next)
435 if lmdb.IsNotFound(err) {
436 return nil
437 }
438 if err != nil {
439 return err
440 }
441
442 fmt.Printf("%s %s\n", k, v)
443 }
444 })
445 }
446
447 // This simple example shows how to iterate a database in reverse. As when
448 // passing the Next flag, the Prev flag may be used without an initial call
449 // using Last.
450 func ExampleCursor_Get_reverse() {
451 err = env.View(func(txn *lmdb.Txn) (err error) {
452 cur, err := txn.OpenCursor(dbi)
453 if err != nil {
454 return err
455 }
456 defer cur.Close()
457
458 for {
459 k, v, err := cur.Get(nil, nil, lmdb.Prev)
460 if lmdb.IsNotFound(err) {
461 return nil
462 }
463 if err != nil {
464 return err
465 }
466
467 fmt.Printf("%s %s\n", k, v)
468 }
469 })
470 }
471
472 // This example shows how duplicates can be processed using LMDB. It is
473 // possible to iterate all key-value pairs (including duplicate key values) by
474 // passing Next. But if special handling of duplicates is needed it may be
475 // beneficial to use NextNoDup or NextDup.
476 func ExampleCursor_Get_dupSort() {
477 err = env.View(func(txn *lmdb.Txn) (err error) {
478 cur, err := txn.OpenCursor(dbi)
479 if err != nil {
480 return err
481 }
482
483 for {
484 k, v, err := cur.Get(nil, nil, lmdb.NextNoDup)
485 if lmdb.IsNotFound(err) {
486 // the database was exausted
487 return nil
488 } else if err != nil {
489 return err
490 }
491
492 // process duplicates
493 var dups [][]byte
494 for {
495 dups = append(dups, v)
496
497 _, v, err = cur.Get(nil, nil, lmdb.NextDup)
498 if lmdb.IsNotFound(err) {
499 break
500 } else if err != nil {
501 return err
502 }
503 }
504
505 log.Printf("%q %q", k, dups)
506 }
507 })
508 }
509
510 // This simple example shows how to iterate a database opened with the
511 // DupSort|DupSort flags. It is not necessary to use the GetMultiple flag
512 // before passing the NextMultiple flag.
513 func ExampleCursor_Get_dupFixed() {
514 err = env.View(func(txn *lmdb.Txn) (err error) {
515 cur, err := txn.OpenCursor(dbi)
516 if err != nil {
517 return err
518 }
519 defer cur.Close()
520
521 for {
522 k, first, err := cur.Get(nil, nil, lmdb.NextNoDup)
523 if lmdb.IsNotFound(err) {
524 return nil
525 }
526 if err != nil {
527 return err
528 }
529
530 stride := len(first)
531
532 for {
533 _, v, err := cur.Get(nil, nil, lmdb.NextMultiple)
534 if lmdb.IsNotFound(err) {
535 break
536 }
537 if err != nil {
538 return err
539 }
540
541 multi := lmdb.WrapMulti(v, stride)
542 for i := 0; i < multi.Len(); i++ {
543 fmt.Printf("%s %s\n", k, multi.Val(i))
544 }
545 }
546 }
547 })
548 }
549
550 // This example shows a trivial case using Renew to service read requests on a
551 // database. Close must be called when the cursor will no longer be renewed.
552 // Before using Renew benchmark your application to understand its benefits.
553 func ExampleCursor_Renew() {
554 var cur *lmdb.Cursor
555 err = env.View(func(txn *lmdb.Txn) (err error) {
556 dbi, err := txn.OpenRoot(0)
557 if err != nil {
558 return err
559 }
560 cur, err = txn.OpenCursor(dbi)
561 return err
562 })
563 if err != nil {
564 panic(err)
565 }
566
567 keys := make(chan []byte)
568 go func() {
569
570 // Close must called when the cursor is no longer needed.
571 defer cur.Close()
572
573 for key := range keys {
574 err := env.View(func(txn *lmdb.Txn) (err error) {
575 err = cur.Renew(txn)
576 if err != nil {
577 return err
578 }
579
580 // retrieve the number of items in the database with the given
581 // key (DupSort).
582 count := uint64(0)
583 _, _, err = cur.Get(key, nil, lmdb.SetKey)
584 if lmdb.IsNotFound(err) {
585 err = nil
586 } else if err == nil {
587 count, err = cur.Count()
588 }
589 if err != nil {
590 return err
591 }
592
593 log.Printf("%d %q", count, key)
594
595 return nil
596 })
597 if err != nil {
598 panic(err)
599 }
600 }
601 }()
602
603 // ...
604 }
605
606 // This example shows how to write a page of contiguous, fixed-size values to a
607 // database opened with DupSort|DupFixed. It doesn't matter if the values are
608 // sorted. Values will be stored in sorted order.
609 func ExampleCursor_PutMulti() {
610 key := []byte("k")
611 items := [][]byte{
612 []byte("v0"),
613 []byte("v2"),
614 []byte("v1"),
615 }
616 page := bytes.Join(items, nil)
617 stride := 2
618
619 err = env.Update(func(txn *lmdb.Txn) (err error) {
620 cur, err := txn.OpenCursor(dbi)
621 if err != nil {
622 return err
623 }
624 defer cur.Close()
625
626 return cur.PutMulti(key, page, stride, 0)
627 })
628 }
629
630 // This example demonstrates how to delete all elements in a database with a
631 // key less than a given value (an RFC3339 timestamp in this case).
632 func ExampleCursor_Del() {
633 before := []byte("2014-05-06T03:04:02Z")
634 err = env.Update(func(txn *lmdb.Txn) (err error) {
635 cur, err := txn.OpenCursor(dbi)
636 if err != nil {
637 return err
638 }
639 defer cur.Close()
640
641 for {
642 k, _, err := cur.Get(nil, nil, lmdb.Next)
643 if lmdb.IsNotFound(err) {
644 return nil
645 }
646 if err != nil {
647 return err
648 }
649
650 if bytes.Compare(k, before) != -1 {
651 return nil
652 }
653
654 err = cur.Del(0)
655 if err != nil {
656 return err
657 }
658 }
659 })
660 }
661
662 // If the database being opened is known to exist then no flags need to be
663 // passed.
664 func ExampleTxn_OpenDBI() {
665 // DBI handles can be saved after their opening transaction has committed
666 // and may be reused as long as the environment remains open.
667 err = env.Update(func(txn *lmdb.Txn) (err error) {
•668 _, err = txn.OpenDBI("dbfound", 0)
669 return err
670 })
671 if err != nil {
672 panic(err)
673 }
674 }
675
676 // When Create is passed to Txn.OpenDBI() the database will be created if it
677 // didn't already exist. An error will be returned if the name is occupied by
678 // data written by Txn./Cursor.Put().
679 func ExampleTxn_OpenDBI_create() {
680 err = env.Update(func(txn *lmdb.Txn) (err error) {
•681 _, err = txn.OpenDBI("dbnew", lmdb.Create)
682 return err
683 })
684 if err != nil {
685 panic(err)
686 }
687 }
688
689 // When a non-existent database is opened without the Create flag the errno is
690 // NotFound. If an application needs to handle this case the function
691 // IsNotFound() will test an error for this condition.
692 func ExampleTxn_OpenDBI_notFound() {
693 err = env.Update(func(txn *lmdb.Txn) (err error) {
•694 _, err = txn.OpenDBI("dbnotfound", 0)
695 return err
696 })
697 log.Print(err) // mdb_dbi_open: MDB_NOTFOUND: No matching key/data pair found
698 }
699
700 // When the number of open named databases in an environment reaches the value
701 // specified by Env.SetMaxDBs() attempts to open additional databases will
702 // return an error with errno DBsFull. If an application needs to handle this
703 // case then the function IsError() can test an error for this condition.
704 func ExampleTxn_OpenDBI_dBsFull() {
705 err = env.Update(func(txn *lmdb.Txn) (err error) {
•706 _, err = txn.OpenDBI("dbnotexist", 0)
707 return err
708 })
709 log.Print(err) // mdb_dbi_open: MDB_DBS_FULL: Environment maxdbs limit reached
710 }
711
712 // Txn.OpenRoot does not need to be called with the Create flag. And
713 // Txn.OpenRoot, unlike Txn.OpenDBI, will never produce the error DBsFull.
714 func ExampleTxn_OpenRoot() {
715 err = env.Update(func(txn *lmdb.Txn) (err error) {
•716 _, err = txn.OpenRoot(0)
717 return err
718 })
719 if err != nil {
720 panic(err)
721 }
722 }
723
724 // Txn.OpenRoot may also be called without flags inside View transactions
725 // before being openend in an Update transaction.
726 func ExampleTxn_OpenRoot_view() {
727 err = env.View(func(txn *lmdb.Txn) (err error) {
728 dbi, err := txn.OpenRoot(0)
729 if err != nil {
730 return err
731 }
732 cur, err := txn.OpenCursor(dbi)
733 if err != nil {
734 return err
735 }
736 for {
737 k, v, err := cur.Get(nil, nil, lmdb.Next)
738 if lmdb.IsNotFound(err) {
739 return nil
740 }
741 if err != nil {
742 return err
743 }
744
745 log.Printf("%s=%s\n", k, v)
746 // ...
747 }
748 })
749 if err != nil {
750 // ...
751 }
752 }
753
754 // This example shows how to properly handle data retrieved from the database
755 // and applies to Txn.Get() as well as Cursor.Get(). It is important to handle
756 // data retreival carefully to make sure the application does not retain
757 // pointers to memory pages which may be reclaimed by LMDB after the
758 // transaction terminates. Typically an application would define helper
759 // functions/methods to conveniently handle data safe retrieval.
760 func ExampleTxn_Get() {
761 // variables to hold data extracted from the database
762 var point struct{ X, Y int }
•763 var p1 []byte
764
765 // extract data from an example environment/database. it is critical for application
766 // code to handle errors but that is omitted here to save space.
767 EnvEx.View(func(txn *lmdb.Txn) (err error) {
768 // OK
769 // A []byte to string conversion will always copy the data
770 v, _ := txn.Get(DBIEx, []byte("mykey"))
771
772 // OK
773 // If []byte is the desired data type then an explicit copy is required
774 // for safe access after the transaction returns.
775 v, _ = txn.Get(DBIEx, []byte("mykey"))
776 p1 = make([]byte, len(v))
777 copy(p1, v)
778
779 // OK
780 // The data does not need be copied because it is parsed while txn is
781 // open.
782 v, _ = txn.Get(DBIEx, []byte("mykey"))
783 _ = json.Unmarshal(v, &point)
784
785 // BAD
786 // Assigning the result directly to p2 leaves its pointer volatile
787 // after the transaction completes which can result in unpredictable
788 // behavior.
•789 _, _ = txn.Get(DBIEx, []byte("mykey"))
790
791 return nil
792 })
793 }
794
795 // This example demonstrates the use of PutReserve to store a string value in
796 // the root database. This may be faster than Put alone for large values
797 // because a string to []byte conversion is not required.
798 func ExampleTxn_PutReserve() {
799 EnvEx.Update(func(txn *lmdb.Txn) (err error) {
800 dbroot, err := txn.OpenRoot(0)
801 if err != nil {
802 return err
803 }
804
805 valstr := "value"
806 p, err := txn.PutReserve(dbroot, []byte("key"), len(valstr), 0)
807 if err != nil {
808 return err
809 }
810 copy(p, valstr)
811
812 return nil
813 })
814 }