returns the last log entry
@param fs
@param lockFile
@return
@throws IOException
187271
public static LogEntry getLastEntry(FileSystem fs, Path lockFile)
          throws IOException {
    FSDataInputStream in = fs.open(lockFile);
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String lastLine = null;
    for(String line = reader.readLine(); line!=null; line = reader.readLine() ) {
      lastLine=line;
    }
    return LogEntry.deserialize(lastLine);
  }
481931
void fsync(String src, String clientName) throws IOException {

    NameNode.stateChangeLog.info("BLOCK* NameSystem.fsync: file "
      + src + " for " + clientName);
    writeLock();
    try {
      if (isInSafeMode()) {
        throw new SafeModeException("Cannot fsync file " + src, safeMode);
      }
      INodeFileUnderConstruction pendingFile = checkLease(src, clientName);

      // If the block has a length of zero, set it to size 1 so 
      // that lease recovery will not discard it.
      Block last = pendingFile.getLastBlock();
      if (last.getNumBytes() == 0) {
        last.setNumBytes(1);
      }
      dir.persistBlocks(src, pendingFile);
    } finally {
      writeUnlock();
    }
    getEditLog().logSync();
  }
906558
public void getPersistentData(ObjectOutputStream oos)
  {
    if (tc.isEntryEnabled())
      SibTr.entry(tc, "getPersistentData", oos);

    try
    {
      HashMap hm = new HashMap();

      if (durablePseudoDestID != null)
        hm.put("durablePseudoDestID", durablePseudoDestID.toByteArray());
      if (durableSubName != null)
        hm.put("durableSubName", durableSubName);
      
      oos.writeObject(hm);
    }
    catch (IOException e)
    {
      // FFDC
      FFDCFilter.processException(
        e,
        "com.ibm.ws.sib.processor.impl.store.itemstreams.AOContainerItemStream.getPersistentData",
        "1:113:1.13",
        this);
        
      SIErrorException e2 = new SIErrorException(e);
      SibTr.exception(tc, e2);
      if (tc.isEntryEnabled()) SibTr.exit(tc, "getPersistentData", e2);
      throw e2;
    }

    if (tc.isEntryEnabled())
      SibTr.exit(tc, "getPersistentData");
  }
866809
@Override
    public List<MonitorLine> getLastLine(Integer count) throws Exception {
        String line;
        final List<MonitorLine> result = new ArrayList<MonitorLine>();
        BufferedReader in = null;
        try {
            in = new BufferedReader(new FileReader(getFilename()));
            int i = 0;
            line = in.readLine();
            while (line != null) {
                result.add(new MonitorLine(i, line));
                i++;
                line = in.readLine();
            }
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ignore) {
            }
        }
        if (result.size() <= count) {
            return result;
        } else {
            return result.subList(result.size() - count, result.size());
        }
    }
1116579
private long findMaxTransaction()
      throws IOException {
    for (EditLogFile elf : getLogFiles(0)) {
      if (elf.isInProgress()) {
        maxSeenTransaction = Math.max(elf.getFirstTxId(), maxSeenTransaction);
      }
      maxSeenTransaction = Math.max(elf.getLastTxId(), maxSeenTransaction);
    }
    return maxSeenTransaction;
  }
1078657
@Override
    public File findNext(File current, long timelimit) {
        File[] files = listFiles(filter);
        File result = null;

        long min = Long.MAX_VALUE;
        long cur = current == null ? Long.MIN_VALUE : getLogFileTimestamp(current);
        for (File file : files) {
            long time = getLogFileTimestamp(file);
            // Select file with a smallest time stamp bigger than time stamp of the 'current' file.
            if (cur < time && time < min) {
                min = time;
                result = file;
            }
        }
        // return 'null' if found file has time stamp outside of the time limit.
        return timelimit > 0 && timelimit < min ? null : result;
    }
468344
public static FileLock getFileLock(java.io.RandomAccessFile file, String fileName) throws java.io.IOException
    {
        return (FileLock) Utils.getImpl("com.ibm.ws.objectManager.utils.FileLockImpl",
                                        new Class[] { java.io.RandomAccessFile.class, String.class },
                                        new Object[] { file, fileName });
    }
490160
static void writeLastTxidToZookeeper(long lastTxid, long totalBlocks,
      long totalInodes, long ssid, Configuration startupConf,
      Configuration confg) throws IOException {
    AvatarZooKeeperClient zk = null;
    LOG.info("Writing lastTxId: " + lastTxid + ", total blocks: " + totalBlocks
        + ", total inodes: " + totalInodes);
    if (lastTxid < 0) {
      LOG.warn("Invalid last transaction id : " + lastTxid
          + " skipping write to zookeeper.");
      return;
    }
    ZookeeperTxId zkTxid = new ZookeeperTxId(ssid, lastTxid, totalBlocks,
        totalInodes);
    int maxTries = startupConf.getInt("dfs.avatarnode.zk.retries", 3);
    for (int i = 0; i < maxTries; i++) {
      try {
        zk = new AvatarZooKeeperClient(confg, null, false);
        zk.registerLastTxId(startupConf.get(NameNode.DFS_NAMENODE_RPC_ADDRESS_KEY), zkTxid);
        return;
      } catch (Exception e) {
        LOG.error("Got Exception when syncing last txid to zk. Will retry...",
            e);
      } finally {
        shutdownZkClient(zk);
      }
    }
    throw new IOException("Cannot connect to zk");
  }
304762
def getLockFilename(self):
        
        if self.baseFilename.endswith(".log"):
            lock_file = self.baseFilename[:-4]
        else:
            lock_file = self.baseFilename
        lock_file += ".lock"
        lock_path, lock_name = os.path.split(lock_file)
        # hide the file on Unix and generally from file completion
        lock_name = ".__" + lock_name
        return os.path.join(lock_path, lock_name)
905628
public void lock() throws FileLockException, IOException {
        if (mode == AccessMode.READ_ONLY) {
            return;
        }

        for (int retries = 0; retries < max_retries_connect; retries++) {
            try {
                fileLock = channel.lock();
                break; // the lock was succesful
            } catch (OverlappingFileLockException e) {
                try {
                    logger.debug("Can't open file '" + osFile.getAbsolutePath()
                            + "' because it's locked. Waiting {} ms and retry {}", RETRY_CONNECT_WAITTIME,
                            retries);
                    System.runFinalization(); // FORCE FINALIZATION TO COLLECT ALL THE PENDING BUFFERS
                    Thread.sleep(RETRY_CONNECT_WAITTIME);
                } catch (InterruptedException ex) {
                    // will throw a FileLockException further
                }
            }
        }

        if (fileLock == null) {
            this.close();
            throw new FileLockException("File " + osFile.getPath()
                    + " is locked by another process, maybe the database is in use by another process.");
        }
    }
575080
def lock_file(f, block=False):
    
    try:
        flags = fcntl.LOCK_EX
        if not block:
            flags |= fcntl.LOCK_NB
        fcntl.flock(f.fileno(), flags)
    except IOError as e:
        if e.errno in (errno.EACCES, errno.EAGAIN):
            raise SystemExit("ERROR: %s is locked by another process." %
                             f.name)
        raise
60095
public static DirLock takeOwnershipIfStale(FileSystem fs, Path dirToLock, int lockTimeoutSec) {
    Path dirLockFile = getDirLockFile(dirToLock);

    long now =  System.currentTimeMillis();
    long expiryTime = now - (lockTimeoutSec*1000);

    try {
      long modTime = fs.getFileStatus(dirLockFile).getModificationTime();
      if(modTime <= expiryTime) {
        return takeOwnership(fs, dirLockFile);
      }
      return null;
    } catch (IOException e)  {
      return  null;
    }
  }
323183
public function getLockLifetime($lockFile)
    {
        if (!file_exists($lockFile)) {
            return 0;
        }

        $pid = file_get_contents($lockFile);
        if (empty($pid)) {
            return 0;
        }

        if (!posix_kill(intval($pid), 0)) {
            return 0;
        }

        $stat = stat($lockFile);

        return (time() - $stat["mtime"]);
    }
879264
private HashtableEntry findEntry(Object key, int retrieveMode, boolean checkExpired)
                    throws IOException,
                    EOFException,
                    FileManagerException,
                    ClassNotFoundException,
                    HashtableOnDiskException {
        if (key == null) {
            return null;
        }

        int hashcode = key.hashCode();
        int index = header.getHtIndex(hashcode, header.currentTableId());
        long current = 0;
        HashtableEntry answer = null;

        if (header.rehashInProgress == 1) {

            if (debug)
                print("*");

            //
            // First search primary table.
            //
            if (htindex[index] != 0) {
                if (debug)
                    print("A");
                current = htindex[index];

                if (current == 0) {
                    throw new IllegalStateException("findEntry: ht pointer is null");
                }
                answer = findEntry(key, hashcode, retrieveMode, checkExpired, current, header.currentTableId());
                if (answer != null) {
                    return answer;
                }
            }

            //
            // Fell through, now search new table
            //
            index = header.getHtIndex(hashcode, header.alternateTableId());
            if (new_htindex[index] != 0) {
                if (debug)
                    print("B ");
                current = new_htindex[index];
                if (current == 0) {
                    throw new IllegalStateException("findEntry: ht pointer is null");
                }
                return findEntry(key, hashcode, retrieveMode, checkExpired, current, header.alternateTableId());
            }
            //
            // Fell through again, nothing here.
            //
            return null;
        } else {
            if (htindex[index] == 0) {
                return null;
            }
            int tableid = header.currentTableId();
            //current = header.calcOffset(index, tableid);
            current = htindex[index];
            if (current == 0) {
                throw new IllegalStateException("findEntry: ht pointer is null");
            }
            return findEntry(key, hashcode, retrieveMode, checkExpired, current, tableid);
        }
    }
1048462
function getCurrentFileSize(counter, timeout, cb) {
  var fd = fs.openSync(__filename, 'r');

  console.log("Trying to aquire lock for the %s time", counter);

  fs.flock(fd, 'exnb', function(err) {
    if (err) {
      return console.log("Couldn't lock file", counter);
    }

    console.log('Aquired lock', counter);

    // unlock after `timeout`
    setTimeout(function() {
      fs.flock(fd, 'un', function(err) {
        if (err) {
          return console.log("Couldn't unlock file", counter);
        }

        if (cb) { cb(); }
      });
    }, timeout);
  });
}
792631
public OFile unlock(final FileLock iLock) throws IOException {
    if (iLock != null) {
      try {
        iLock.release();
      } catch (ClosedChannelException e) {
      }
    }
    return this;
  }
943618
private double getFileAge(File file) {
        final Date d = new Date();
        final long modified = file.lastModified();
        final double time = (d.getTime() - modified) / 1000.0 / 60.0;
        LOGGER.debug("Lock file age is {} minutes", time);
        return time;
    }