Merge pull request #7 from fengjingchao/fileSystem

add acl doc after merge
This commit is contained in:
Xiang Li 2013-09-08 07:05:54 -07:00
commit b7358ccd98
3 changed files with 48 additions and 10 deletions

View File

@ -65,7 +65,36 @@ Besides the file and directory difference, all nodes have common attributes and
Set the node's expiration time to (current time + ttl)
## ACL
### Theory
Etcd exports a Unix-like file system interface consisting of files and directories, collectively called nodes.
Each node has various meta-data, including three names of access control lists used to control reading, writing and changing (change ACL names for the node).
We are storing the ACL names for nodes under a special *ACL* directory.
Each node has ACL name corresponding to one file within *ACL* dir.
Unless overridden, a node naturally inherits the ACL names of its parent directory on creation.
For each ACL name, it has three children: *R (Reading)*, *W (Writing)*, *C (Changing)*
Each permission is also a node. Under the node it contains the users who have this permission for the file refering to this ACL name.
### Example
[TODO]
### Diagram
[TODO]
### Interface
Testing permissions:
- (node *Node) get_perm()
- (node *Node) has_perm(perm string, user string)
Setting/Changing permissions:
- (node *Node) set_perm(perm string)
- (node *Node) change_ACLname(aclname string)
## User Group
[TODO]

View File

@ -49,17 +49,21 @@ type eventQueue struct {
events []*Event
size int
front int
back int
capacity int
}
func (eq *eventQueue) back() int {
return (eq.front + eq.size - 1 + eq.capacity) % eq.capacity
}
func (eq *eventQueue) insert(e *Event) {
eq.back = (eq.back + 1) % eq.capacity
eq.events[eq.back] = e
index := (eq.back() + 1) % eq.capacity
eq.events[index] = e
if eq.size == eq.capacity { //dequeue
eq.front = (eq.back + 1) % eq.capacity
eq.front = (index + 1) % eq.capacity
} else {
eq.size++
}
@ -77,7 +81,6 @@ func newEventHistory(capacity int) *EventHistory {
Queue: eventQueue{
capacity: capacity,
events: make([]*Event, capacity),
back: -1,
},
}
}
@ -92,27 +95,29 @@ func (eh *EventHistory) addEvent(e *Event) {
eh.StartIndex = eh.Queue.events[eh.Queue.front].Index
}
// scan function is enumerating events from the index in history and
// stops till the first point where the key has identified prefix
func (eh *EventHistory) scan(prefix string, index uint64) (*Event, error) {
eh.rwl.RLock()
defer eh.rwl.RUnlock()
start := index - eh.StartIndex
if start < 0 {
// the index should locate after the event history's StartIndex
// and before its size
if start < 0 {
// TODO: Add error type
return nil, nil
}
if start >= uint64(eh.Queue.size) {
return nil, nil
}
i := int((start + uint64(eh.Queue.front)) % uint64(eh.Queue.capacity))
for {
e := eh.Queue.events[i]
if strings.HasPrefix(e.Key, prefix) {
return e, nil
@ -120,7 +125,7 @@ func (eh *EventHistory) scan(prefix string, index uint64) (*Event, error) {
i = (i + 1) % eh.Queue.capacity
if i == eh.Queue.back {
if i == eh.Queue.back() {
// TODO: Add error type
return nil, nil
}

View File

@ -19,12 +19,16 @@ func TestEventQueue(t *testing.T) {
// Test
j := 100
for i := eh.Queue.front; i != eh.Queue.back; i = (i + 1) % eh.Queue.capacity {
i := eh.Queue.front
n := eh.Queue.size
for ; n > 0; n-- {
e := eh.Queue.events[i]
if e.Index != uint64(j) {
t.Fatalf("queue error!")
}
j++
i = (i + 1) % eh.Queue.capacity
}
}