-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathEngineInterface.wiki
675 lines (431 loc) · 21.7 KB
/
EngineInterface.wiki
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
{{{
Network Working Group Norbye, Ed.
Internet-Draft Sun Microsystems, INC
Intended status: Informational Maesaka, Ed.
Expires: June 21, 2009 mixi, INC
December 18, 2008
Memcache Engine Interface
draft-norbye-engine-interface-02
Status of this Memo
This document is an Internet-Draft and is NOT offered in accordance
with Section 10 of RFC 2026, and the author does not provide the IETF
with any rights other than to publish as an Internet-Draft.
Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF), its areas, and its working groups. Note that
other groups may also distribute working documents as Internet-
Drafts.
Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."
The list of current Internet-Drafts can be accessed at
http://www.ietf.org/ietf/1id-abstracts.txt.
The list of Internet-Draft Shadow Directories can be accessed at
http://www.ietf.org/shadow.html.
This Internet-Draft will expire on June 21, 2009.
Abstract
This memo describes the engine interface.
Norbye & Maesaka Expires June 21, 2009 [Page 1]
Internet-Draft Memcache Engine Interface December 2008
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1. Conventions Used In This Document . . . . . . . . . . . . 3
2. Data structures . . . . . . . . . . . . . . . . . . . . . . . 3
2.1. Error codes . . . . . . . . . . . . . . . . . . . . . . . 3
2.2. Store operations . . . . . . . . . . . . . . . . . . . . . 3
2.3. rel_time_t . . . . . . . . . . . . . . . . . . . . . . . . 3
2.4. struct item . . . . . . . . . . . . . . . . . . . . . . . 4
2.5. Interface structure . . . . . . . . . . . . . . . . . . . 5
3. Create instance . . . . . . . . . . . . . . . . . . . . . . . 5
4. Interface structure v. 1 . . . . . . . . . . . . . . . . . . . 5
4.1. interface . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2. get_info . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.3. initialize . . . . . . . . . . . . . . . . . . . . . . . . 7
4.4. destroy . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.5. item_allocate . . . . . . . . . . . . . . . . . . . . . . 7
4.6. item_delete . . . . . . . . . . . . . . . . . . . . . . . 8
4.7. item_release . . . . . . . . . . . . . . . . . . . . . . . 8
4.8. get . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.9. get_stats . . . . . . . . . . . . . . . . . . . . . . . . 9
4.10. store . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.11. arithmetic . . . . . . . . . . . . . . . . . . . . . . . . 10
4.12. flush . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.13. touch . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5. Asynchronous interface . . . . . . . . . . . . . . . . . . . . 11
6. Security Considerations . . . . . . . . . . . . . . . . . . . 12
7. Normative References . . . . . . . . . . . . . . . . . . . . . 12
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 12
Norbye & Maesaka Expires June 21, 2009 [Page 2]
Internet-Draft Memcache Engine Interface December 2008
1. Introduction
1.1. Conventions Used In This Document
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in [KEYWORDS].
2. Data structures
2.1. Error codes
The engine interface defines the enum ENGINE_ERROR_CODE with the
following valid error messages:
ENGINE_SUCCESS The command executed successfully
ENGINE_KEY_ENOENT The key does not exists
ENGINE_KEY_EEXISTS The key already exists
ENGINE_ENOMEM Could not allocate memory
ENGINE_NOT_STORED The item was not stored
ENGINE_EINVAL Invalid arguments
ENGINE_ENOTSUP The engine does not support this
ENGINE_EWOULDBLOCK This would cause the engine to block
ENGINE_E2BIG The data is too big for the engine
2.2. Store operations
The engine interface defines the enum ENGINE_STORE_OPERATION with the
following values:
OPERATION_ADD TODO: fillme!!
OPERATION_SET
OPERATION_REPLACE
OPERATION_APPEND
OPERATION_PREPEND
OPERATION_CAS
2.3. rel_time_t
Items will only expire some time in the future, and the rel_time_t is
a datatype to represent a time period relative to process startup
time.
rel_time_t
typedef uint32_t rel_time_t;
Norbye & Maesaka Expires June 21, 2009 [Page 3]
Internet-Draft Memcache Engine Interface December 2008
2.4. struct item
Each "key-value" pair stored in memcached is represented with an item
structure consisting of a fixed part and a variable part. This might
sound unnecessary complex, but adds extra flexibility for the various
storage engines.
The fixed part of the item structure consists of:
struct item
typedef struct {
rel_time_t exptime;
uint32_t nbytes;
uint32_t flags;
uint16_t nkey;
uint16_t iflag;
} item;
exptime When the item will expire (relative to process
startup)
nbytes The total size of the data (in bytes)
flags Flags associated with the item
nkey The total length of the key (in bytes)
iflag Item flags describing the content of the item
structure. The upper 8 bits is reserved for the
storage engine to use
The variable part of the item structure contains the following
optional data. Please note that the optional fields MUST be present
in the specified order.
struct item variable data
cas_id Optional, stored as uint64_t
inline key Optional, stored as n bytes containing the key
pointer to key Optional, stored as a void*
inline data Optional, stored as n bytes containing the data
padding Optional, stored as n bytes
pointer to data Optional, Stored as a void*
cas_id Only present if iflag & ITEM_WITH_CAS
inline key Present if !(iflag & ITEM_KEY_PTR)
pointer to key Present if iflag & ITEM_KEY_PTR
Norbye & Maesaka Expires June 21, 2009 [Page 4]
Internet-Draft Memcache Engine Interface December 2008
inline data Present if !(iflag & ITEM_DATA_PTR)
padding Only present if !(iflag & ITEM_KEY_PTR) && (iflag
& ITEM_DATA_PTR)
pointer to data Present if iflag & ITEM_DATA_PTR
The size of the padding is (sizeof(void*) - (nkey % sizeof(void*))
2.5. Interface structure
All communication with the storage engine will go through the engine
interface structure. This is defined as an extendible structure to
allow future modifications and preserve binary backwards
compatibility.
struct engine_interface
typedef struct engine_interface{
uint64_t interface;
} ENGINE_HANDLE;
3. Create instance
Each shared object providing an implementation of the storage
interface must export the following function to allow memcached to
create a handle to the storage interface:
ENGINE_ERROR_CODE create_instance(uint64_t interface,
ENGINE_HANDLE** handle);
interface The highest interface level the server supports
handle Where to store the interface handle
4. Interface structure v. 1
Engine interface version 1
typedef struct engine_interface_v1 {
struct engine_interface interface;
const char* (*get_info)(ENGINE_HANDLE* handle);
ENGINE_ERROR_CODE (*initialize)(ENGINE_HANDLE* handle,
const char* config_str);
void (*destroy)(ENGINE_HANDLE* handle);
ENGINE_ERROR_CODE (*item_allocate)(ENGINE_HANDLE* handle,
const void* cookie,
item **item,
const void* key,
Norbye & Maesaka Expires June 21, 2009 [Page 5]
Internet-Draft Memcache Engine Interface December 2008
const size_t nkey,
const size_t nbytes,
const int flags,
const rel_time_t exptime);
ENGINE_ERROR_CODE (*item_delete)(ENGINE_HANDLE* handle,
const void* cookie,
item* item);
void (*item_release)(ENGINE_HANDLE* handle, item* item);
ENGINE_ERROR_CODE (*get)(ENGINE_HANDLE* handle,
const void* cookie,
item** item,
const void* key,
const int nkey);
char *(*get_stats)(ENGINE_HANDLE* handle,
const char *stat_key,
int nkey,
uint32_t (*callback)(char *buf,
const char *key,
const uint16_t klen,
const char *val,
const uint32_t vlen,
void *cookie),
const void *cookie,
int *buflen);
ENGINE_ERROR_CODE (*store)(ENGINE_HANDLE* handle,
const void *cookie,
item* item,
enum operation operation);
ENGINE_ERROR_CODE (*arithmetic)(ENGINE_HANDLE* handle,
const void* cookie,
const void* key,
const int nkey,
const bool increment,
const bool create,
const uint64_t delta,
const uint64_t initial,
const rel_time_t exptime,
uint64_t *cas,
uint64_t *result);
ENGINE_ERROR_CODE (*flush)(ENGINE_HANDLE* handle,
const void* cookie, time_t when);
ENGINE_ERROR_CODE (*touch)(ENGINE_HANDLE* handle,
const void* cookie,
item *item,
const rel_time_t newtime);
} ENGINE_HANDLE_V1;
Norbye & Maesaka Expires June 21, 2009 [Page 6]
Internet-Draft Memcache Engine Interface December 2008
4.1. interface
To preserve binary compatibility this member MUST be first in the
structure. An engine implementing this interface MUST set the
interface member to the value 1.
4.2. get_info
Get information about this storage engine (to use in the version
command). The core server will NOT try to release the memory
returned, so the engine SHOULD reuse this buffer to aviod memory
leakage.
const char* (*get_info)(ENGINE_HANDLE* handle);
handle Pointer to the engine
4.3. initialize
Called during initialization of memcached. The engine should do all
of its initalization in this routine.
ENGINE_ERROR_CODE (*initialize)(ENGINE_HANDLE* handle,
const char* config_str);
handle Pointer to the engine
config_str String containing configuration options
4.4. destroy
Called during shutdown of memcached. The engine should release all
resources and perform shutdown logic in this routine.
void (*destroy)(ENGINE_HANDLE* handle);
handle Pointer to the engine
4.5. item_allocate
Allocate space to store an item.
ENGINE_ERROR_CODE (*item_allocate)(ENGINE_HANDLE* handle,
const void* cookie,
item **item,
const void* key,
const size_t nkey,
const size_t nbytes.
const int flags,
Norbye & Maesaka Expires June 21, 2009 [Page 7]
Internet-Draft Memcache Engine Interface December 2008
const rel_time_t exptime);
handle Pointer to the engine
cookie Cookie for the engine to use with
ENGINE_EWOULDBLOCK
item Where to store the result
key Pointer to the key
nkey The length of the key
nbytes The number of bytes in the data
flags The flags to store with the item
exptime When the item will expire
4.6. item_delete
Delete an item.
ENGINE_ERROR_CODE (*item_delete)(ENGINE_HANDLE* handle,
const void* cookie,
item* item);
handle Pointer to the engine
cookie Cookie for the engine to use with
ENGINE_EWOULDBLOCK
item The item to delete
4.7. item_release
Release an item. The core server will no longer reference the
object, so the engine may release or modify it.
void (*item_release)(ENGINE_HANDLE* handle, item* item);
handle Pointer to the engine
item The item to release
4.8. get
Get an item identified by a key
ENGINE_ERROR_CODE (*get)(ENGINE_HANDLE* handle,
const void* cookie,
item** item,
const void* key,
const int nkey);
Norbye & Maesaka Expires June 21, 2009 [Page 8]
Internet-Draft Memcache Engine Interface December 2008
handle Pointer to the engine
cookie Cookie for the engine to use with
ENGINE_EWOULDBLOCK
item Where to store the result
key Pointer to the key
nkey The length of the key
4.9. get_stats
Query the engine for statistics. This function returns a pointer to
a buffer with series of pipelined return packets. Each packet
represents a single row of stats.
char *(*get_stats)(ENGINE_HANDLE* handle,
const char *stat_key,
int nkey,
uint32_t (*callback)(char *buf,
const char *key,
const uint16_t klen,
const char *val,
const uint32_t vlen,
void *cookie),
const void *cookie,
int *buflen);
handle Pointer to the engine
stat_key Specifies what kind of stats to fetch
nkey The length of stat_key
callback Callback to use to create the result
cookie Cookie for the engine that MUST be provided as
the cookie in the callback to the server
buflen Size of the result that MUST be set in bytes
An engine SHOULD NOT implement its own result serializer and instead
use the provided callback function. When allocating memory for the
result buffer, make sure to take into account the 24 byte overhead
per stat entry and the termination packet for the binary protocol.
The termination packet is also 24 bytes.
Details on the callback is as follows:
uint32_t (*callback)(char *buf,
const char *key,
const uint16_t klen,
const char *val,
const uint32_t vlen,
Norbye & Maesaka Expires June 21, 2009 [Page 9]
Internet-Draft Memcache Engine Interface December 2008
void *cookie);
buf Buffer to write to which the engine MUST allocate
key Name of the statistic
klen The length of the key
val The value of the statistic
vlen The length of the value
cookie Cookie returned by the engin
The callback returns the number of bytes it had written to the
buffer.
4.10. store
Store an item in the cache.
ENGINE_ERROR_CODE (*store)(ENGINE_HANDLE* handle,
const void *cookie,
item* item,
enum operation operation);
handle Pointer to the engine
cookie Cookie for the engine to use with
ENGINE_EWOULDBLOCK
item The item to store
operation ADD / SET / REPLACE
4.11. arithmetic
Perform arithmetic operation (increment / decrement) on the value of
a key.
ENGINE_ERROR_CODE (*arithmetic)(ENGINE_HANDLE* handle,
const void* cookie,
const void* key,
const int nkey,
const bool increment,
const bool create,
const uint64_t delta,
const uint64_t initial,
const rel_time_t exptime,
uint64_t *cas,
uint64_t *result);
Norbye & Maesaka Expires June 21, 2009 [Page 10]
Internet-Draft Memcache Engine Interface December 2008
handle Pointer to the engine
cookie Cookie for the engine to use with
ENGINE_EWOULDBLOCK
key The key to operate on
nkey The length of the key
increment TRUE if increment, FALSE to decrement
create Set to TRUE if we should create nonexisting keys
delta The amount to increment / decrement
initial The initial value if we create the key
exptime When the item shall expire
cas IN: the current CAS value, OUT: the resulting CAS
value
result OUT: The resulting value
4.12. flush
Flush all items from the cache
ENGINE_ERROR_CODE (*flush)(ENGINE_HANDLE* handle,
const void *cookie,
time_t when);
handle Pointer to the engine
cookie Cookie for the engine to use with
ENGINE_EWOULDBLOCK
when When to flush the cache (see the protocol spec)
4.13. touch
Set the last referenced time for an object
ENGINE_ERROR_CODE (*touch)(ENGINE_HANDLE* handle,
const void* cookie,
item* item,
const rel_time_t newtime);
handle Pointer to the engine
cookie Cookie for the engine to use with
ENGINE_EWOULDBLOCK
item The item to update
newtime The new time to use for the item
5. Asynchronous interface
An engine should return ENGINE_EWOULDBLOCK if it cannot return
immediately from the request. It may then perform all the operations
it may want to in another thread, and call:
Norbye & Maesaka Expires June 21, 2009 [Page 11]
Internet-Draft Memcache Engine Interface December 2008
void notify_io_complete(const void* cookie,
ENGINE_ERROR_CODE status);
cookie Cookie for the engine to use with
ENGINE_EWOULDBLOCK
status The status for the IO operation
The memcached server will then retry the operation.
6. Security Considerations
Memcache has no authentication or security layers whatsoever. It is
RECOMMENDED that memcache be deployed strictly on closed, protected,
back-end networks within a single data center, within a single
cluster of servers, or even on a single host, providing shared
caching for multiple applications. Memcache MUST NOT be made
available on a public network.
7. Normative References
[KEYWORDS]
Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, March 1997.
Authors' Addresses
Trond Norbye (editor)
Sun Microsystems, INC
Haakon VII g. 7B
Trondheim NO-7485 Trondheim
Norway
Email: [email protected]
Toru Maesaka (editor)
mixi, INC
Jingumae 2-34-17
Shibuya Tokyo 150-0001
Japan
Email: [email protected]
Norbye & Maesaka Expires June 21, 2009 [Page 12]
}}}