MCPcopy Create free account
hub / github.com/Super-long/ChubbyGo / Acquire

Method Acquire

BaseServer/fileSystem.go:300–333  ·  view source on GitHub ↗

* * @param: 文件描述符传来的InstanceSeq;要删除的文件的名字 * @return: 成功删除返回true,否则返回false * @notes: 需要检测name是否存在; 调用方先判断bool再看seq */

(InstanceSeq uint64, filename string, locktype int, checksum uint64)

Source from the content-addressed store, hash-verified

298 * @notes: 需要检测name是否存在; 调用方先判断bool再看seq
299 */
300func (Fsn *FileSystemNode) Acquire(InstanceSeq uint64, filename string, locktype int, checksum uint64) (uint64, error) {
301 Node, IsExist := Fsn.next[filename]
302
303 if !IsExist {
304 log.Printf("INFO : %s/%s does not exist.\n", Fsn.nowPath, filename)
305 return 0, ChubbyGoFileSystemError(PathError)
306 }
307
308 if checksum != Node.checksum {
309 log.Printf("WARNING : A danger requirment, unmatched checksum, now(%d) -> client(%d).\n", checksum, Node.checksum)
310 return 0, ChubbyGoFileSystemError(CheckSumError)
311 }
312
313 if InstanceSeq < Node.instanceSeq {
314 log.Println("WARNING : Acquire -> Request from a backward file descriptor!")
315 return 0, ChubbyGoFileSystemError(InstanceSeqError)
316 }
317
318 if Node.nowLockType == NotLock {
319 if locktype == ReadLock {
320 Node.readLockReferenceCount++
321 }
322 Node.nowLockType = locktype
323 } else if Node.nowLockType == ReadLock && locktype == ReadLock {
324 Node.readLockReferenceCount++
325 return Node.tokenSeq, nil
326 } else if Node.nowLockType == WriteLock { // 和下面分开写是为了清楚的看到所有情况
327 return 0, ChubbyGoFileSystemError(LockTypeError)
328 } else { // now readLock, args writelock
329 return 0, ChubbyGoFileSystemError(LockTypeError)
330 }
331
332 return Node.tokenSeq, nil // 直接返回当前值,在release的时候加1就可以了
333}
334
335/*
336 * @param: 文件描述符传来的InstanceSeq;要释放的文件(锁)的名字

Callers

nothing calls this directly

Calls 1

ChubbyGoFileSystemErrorTypeAlias · 0.85

Tested by

no test coverage detected