* * @param: 文件描述符传来的InstanceSeq;要释放的文件(锁)的名字 * @return: 成功删除返回true,否则返回false * @notes: 需要检测name是否存在 */
(InstanceSeq uint64, filename string, Token uint64, checksum uint64)
| 338 | * @notes: 需要检测name是否存在 |
| 339 | */ |
| 340 | func (Fsn *FileSystemNode) Release(InstanceSeq uint64, filename string, Token uint64, checksum uint64) error { |
| 341 | Node, IsExist := Fsn.next[filename] |
| 342 | |
| 343 | if !IsExist { |
| 344 | log.Printf("INFO : %s/%s does not exist.\n", Fsn.nowPath, filename) |
| 345 | return ChubbyGoFileSystemError(PathError) |
| 346 | } |
| 347 | |
| 348 | if checksum != Node.checksum { |
| 349 | log.Printf("WARNING : A danger requirment, unmatched checksum, now(%d) -> client(%d).\n", checksum, Node.checksum) |
| 350 | return ChubbyGoFileSystemError(CheckSumError) |
| 351 | } |
| 352 | |
| 353 | // 防止落后的锁持有者删除掉现有的被其他节点持有的锁 |
| 354 | if Token < Node.tokenSeq { |
| 355 | log.Printf("WARNING : Have a lagging client want release file(%s) now(%d) node.clientSeq(%d).\n", Node.nowPath, Token, Node.tokenSeq) |
| 356 | return ChubbyGoFileSystemError(TokenSeqError) |
| 357 | } |
| 358 | |
| 359 | if InstanceSeq < Node.instanceSeq { |
| 360 | log.Println("WARNING : Release -> Request from a backward file descriptor!") |
| 361 | return ChubbyGoFileSystemError(InstanceSeqError) |
| 362 | } |
| 363 | |
| 364 | if Node.nowLockType == NotLock { |
| 365 | log.Println("WARNING : Error operation, release before acquire.") |
| 366 | return ChubbyGoFileSystemError(ReleaseBeforeAcquire) |
| 367 | } else if Node.nowLockType == ReadLock { // TODO 但显然这种做法会使得写操作可能饥饿 |
| 368 | if Node.readLockReferenceCount >= 1 { |
| 369 | Node.readLockReferenceCount-- |
| 370 | } else { // 显然不可能出现这种情况 |
| 371 | log.Println("ERROR : Release -> Impossible situation.") |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | if Node.readLockReferenceCount > 0 { |
| 376 | return nil |
| 377 | } |
| 378 | |
| 379 | // 当前锁定类型是写锁或者读锁引用计数为0,显然当所有的读锁都解锁以后才会递增token |
| 380 | Node.tokenSeq++ |
| 381 | Node.nowLockType = NotLock |
| 382 | |
| 383 | return nil |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | * @param: 文件描述符传来的InstanceSeq;要打开的文件名 |
nothing calls this directly
no test coverage detected