Skip to content

Commit

Permalink
[fix] add range end and lease to txn (#89)
Browse files Browse the repository at this point in the history
* fix models extraction

* add lease and range_end to txn
  • Loading branch information
Revolution1 authored May 8, 2019
1 parent 245565a commit 1d287ef
Show file tree
Hide file tree
Showing 15 changed files with 239 additions and 161 deletions.
8 changes: 4 additions & 4 deletions etcd3/apis/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def role_grant_permission(self, name, key=None, permType=authpbPermissionType.RE
:type name: str
:param name: name is the name of the role which will be granted the permission.
:type key: str
:type key: str or bytes
:param key: the key been granted to the role
:type perm: dict
:param perm: authpbPermissionType.READ or authpbPermissionType.WRITE or authpbPermissionType.READWRITE
:type range_end: str
:type range_end: str or bytes
:param range_end: range_end is the upper bound on the requested range [key, range_end).
If range_end is '\0', the range is all keys >= key.
If range_end is key plus one (e.g., "aa"+1 == "ab", "a\xff"+1 == "b"),
Expand Down Expand Up @@ -133,9 +133,9 @@ def role_revoke_permission(self, role, key=None, range_end=None, prefix=False, a
:type role: str
:param role: the name of the role which will get permission revoked.
:type key: str
:type key: str or bytes
:param key: the key been revoked from the role
:type range_end: str
:type range_end: str or bytes
:param range_end: range_end is the upper bound on the requested range [key, range_end).
If range_end is '\0', the range is all keys >= key.
If range_end is key plus one (e.g., "aa"+1 == "ab", "a\xff"+1 == "b"),
Expand Down
10 changes: 5 additions & 5 deletions etcd3/apis/kv.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def delete_range(self, key=None, range_end=None, prev_kv=False, prefix=False, al
A delete request increments the revision of the key-value store
and generates a delete event in the event history for every deleted key.
:type key: str
:type key: str or bytes
:param key: key is the first key to delete in the range.
:type range_end: str
:type range_end: str or bytes
:param range_end: range_end is the key following the last key to delete for the range [key, range_end).
If range_end is not given, the range is defined to contain only the key argument.
If range_end is one bit larger than the given key, then the range is all the keys
Expand Down Expand Up @@ -72,7 +72,7 @@ def put(self, key, value, lease=0, prev_kv=False, ignore_value=False, ignore_lea
A put request increments the revision of the key-value store
and generates one event in the event history.
:type key: str
:type key: str or bytes
:param key: key is the key, in bytes, to put into the key-value store.
:type value: str
:param value: value is the value, in bytes, to associate with the key in the key-value store.
Expand Down Expand Up @@ -128,9 +128,9 @@ def range(
"""
Range gets the keys in the range from the key-value store.
:type key: str
:type key: str or bytes
:param key: key is the first key for the range. If range_end is not given, the request only looks up key.
:type range_end: str
:type range_end: str or bytes
:param range_end: range_end is the upper bound on the requested range [key, range_end).
If range_end is '\0', the range is all keys >= key.
If range_end is key plus one (e.g., "aa"+1 == "ab", "a\xff"+1 == "b"),
Expand Down
2 changes: 1 addition & 1 deletion etcd3/apis/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def unlock(self, key):
lock. The next Lock caller waiting for the lock will then be
woken up and given ownership of the lock.
:type key: str
:type key: str or bytes
:param key: key is the lock ownership key granted by Lock.
:type lease: int
:param lease: lease is the lease ID to associate with the key in the key-value store. A lease
Expand Down
4 changes: 2 additions & 2 deletions etcd3/apis/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def watch_create(self, key=None, range_end=None, start_revision=None, progress_n
"""
WatchCreate creates a watch stream on given key or key_range
:type key: str
:type key: str or bytes
:param key: key is the key to register for watching.
:type range_end: str
:type range_end: str or bytes
:param range_end: range_end is the end of the range [key, range_end) to watch. If range_end is not given,
only the key argument is watched. If range_end is equal to '\0', all keys greater than
or equal to the key argument are watched.
Expand Down
4 changes: 2 additions & 2 deletions etcd3/baseclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ def Watcher(self, key=None, range_end=None, max_retries=-1, start_revision=None,
"""
Initialize a Watcher
:type key: str
:type key: str or bytes
:param key: key is the key to register for watching.
:type range_end: str
:type range_end: str or bytes
:param range_end: range_end is the end of the range [key, range_end) to watch. If range_end is not given,
only the key argument is watched. If range_end is equal to '\0', all keys greater than
or equal to the key argument are watched.
Expand Down
115 changes: 59 additions & 56 deletions etcd3/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,44 @@ class AlarmRequestAlarmAction(EtcdModel, enum.Enum):
default: GET
"""
GET = 'GET'
ACTIVATE = 'ACTIVATE'
DEACTIVATE = 'DEACTIVATE'
GET = 'GET'


class authpbPermissionType(EtcdModel, enum.Enum):
"""
ref: #/definitions/authpbPermissionType
default: READ
"""
READ = 'READ'
READWRITE = 'READWRITE'
WRITE = 'WRITE'


class EventEventType(EtcdModel, enum.Enum):
class CompareCompareResult(EtcdModel, enum.Enum):
"""
ref: #/definitions/EventEventType
ref: #/definitions/CompareCompareResult
default: PUT
default: EQUAL
"""
DELETE = 'DELETE'
PUT = 'PUT'
EQUAL = 'EQUAL'
GREATER = 'GREATER'
LESS = 'LESS'
NOT_EQUAL = 'NOT_EQUAL'


class RangeRequestSortTarget(EtcdModel, enum.Enum):
class CompareCompareTarget(EtcdModel, enum.Enum):
"""
ref: #/definitions/RangeRequestSortTarget
ref: #/definitions/CompareCompareTarget
default: KEY
default: VERSION
"""
VERSION = 'VERSION'
CREATE = 'CREATE'
KEY = 'KEY'
MOD = 'MOD'
VALUE = 'VALUE'
VERSION = 'VERSION'


class etcdserverpbAlarmType(EtcdModel, enum.Enum):
"""
ref: #/definitions/etcdserverpbAlarmType
default: NONE
"""
NONE = 'NONE'
NOSPACE = 'NOSPACE'
LEASE = 'LEASE'


class CompareCompareResult(EtcdModel, enum.Enum):
class EventEventType(EtcdModel, enum.Enum):
"""
ref: #/definitions/CompareCompareResult
ref: #/definitions/EventEventType
default: EQUAL
default: PUT
"""
EQUAL = 'EQUAL'
GREATER = 'GREATER'
LESS = 'LESS'
NOT_EQUAL = 'NOT_EQUAL'
PUT = 'PUT'
DELETE = 'DELETE'


class RangeRequestSortOrder(EtcdModel, enum.Enum):
Expand All @@ -80,21 +59,22 @@ class RangeRequestSortOrder(EtcdModel, enum.Enum):
default: NONE
"""
NONE = 'NONE'
ASCEND = 'ASCEND'
DESCEND = 'DESCEND'
NONE = 'NONE'


class CompareCompareTarget(EtcdModel, enum.Enum):
class RangeRequestSortTarget(EtcdModel, enum.Enum):
"""
ref: #/definitions/CompareCompareTarget
ref: #/definitions/RangeRequestSortTarget
default: VERSION
default: KEY
"""
KEY = 'KEY'
VERSION = 'VERSION'
CREATE = 'CREATE'
MOD = 'MOD'
VALUE = 'VALUE'
VERSION = 'VERSION'


class WatchCreateRequestFilterType(EtcdModel, enum.Enum):
Expand All @@ -103,31 +83,54 @@ class WatchCreateRequestFilterType(EtcdModel, enum.Enum):
default: NOPUT
"""
NODELETE = 'NODELETE'
NOPUT = 'NOPUT'
NODELETE = 'NODELETE'


class authpbPermissionType(EtcdModel, enum.Enum):
"""
ref: #/definitions/authpbPermissionType
default: READ
"""
READ = 'READ'
WRITE = 'WRITE'
READWRITE = 'READWRITE'


class etcdserverpbAlarmType(EtcdModel, enum.Enum):
"""
ref: #/definitions/etcdserverpbAlarmType
default: NONE
"""
NONE = 'NONE'
NOSPACE = 'NOSPACE'
CORRUPT = 'CORRUPT'


name_to_model = {
'AlarmRequestAlarmAction': AlarmRequestAlarmAction,
'authpbPermissionType': authpbPermissionType,
'EventEventType': EventEventType,
'RangeRequestSortTarget': RangeRequestSortTarget,
'etcdserverpbAlarmType': etcdserverpbAlarmType,
'CompareCompareResult': CompareCompareResult,
'RangeRequestSortOrder': RangeRequestSortOrder,
'CompareCompareTarget': CompareCompareTarget,
'EventEventType': EventEventType,
'RangeRequestSortOrder': RangeRequestSortOrder,
'RangeRequestSortTarget': RangeRequestSortTarget,
'WatchCreateRequestFilterType': WatchCreateRequestFilterType,
'authpbPermissionType': authpbPermissionType,
'etcdserverpbAlarmType': etcdserverpbAlarmType,
}

__all__ = [
'AlarmRequestAlarmAction',
'authpbPermissionType',
'EventEventType',
'RangeRequestSortTarget',
'etcdserverpbAlarmType',
'CompareCompareResult',
'RangeRequestSortOrder',
'CompareCompareTarget',
'EventEventType',
'RangeRequestSortOrder',
'RangeRequestSortTarget',
'WatchCreateRequestFilterType',
'name_to_model',
'authpbPermissionType',
'etcdserverpbAlarmType',
'EtcdModel',
'name_to_model',
]
3 changes: 1 addition & 2 deletions etcd3/stateful/lock.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os
import socket
import tempfile
import threading
import uuid

import six

from .watch import EventType
from ..errors import ErrLeaseNotFound
from ..utils import log
from ..utils import get_ident
from ..utils import log


class EtcdLockError(Exception):
Expand Down
Loading

0 comments on commit 1d287ef

Please sign in to comment.