<commit_before>var locks = require('locks');

//Map lock only used to create new partitionLocks entries
var mapLock = locks.createMutex();
var partitionLocks = new Object();
var timeoutSeconds = 2;

//key is unique for the namespace & partition.
module.exports.lockedOperation = function lockedOperation (key, callback) {
	var keyStr = JSON.stringify(key);
    var keyLock = partitionLocks[keyStr];
    
    // If lock does not exist - acquire the map lock and create new lock for this key
  if (keyLock == null) {
      mapLock.timedLock(timeoutSeconds * 1000, function (error) {
        if (error) {
            console.log('Could not get the partition map mutex lock within ' + timeoutSeconds + ' seconds, so gave up');
        } else {
            if (keyLock == null) {
                 keyLock = locks.createMutex();
                 partitionLocks[keyStr] = keyLock;
                 console.log("Created partition lock object for " + keyStr);
                 mapLock.unlock();
              }
        }
       });
  }
  
  if (keyLock != null) {
     keyLock.timedLock(timeoutSeconds * 1000, function (error) {
       callback();
       keyLock.unlock();
     });
  }
};<commit_msg>Revert "Remove unnecessary lock logging"<commit_after>var locks = require('locks');

//Map lock only used to create new partitionLocks entries
var mapLock = locks.createMutex();
var partitionLocks = new Object();
var timeoutSeconds = 2;

//key is unique for the namespace & partition.
module.exports.lockedOperation = function lockedOperation (key, callback) {
	var keyStr = JSON.stringify(key);
    var keyLock = partitionLocks[keyStr];
    
    // If lock does not exist - acquire the map lock and create new lock for this key
  if (keyLock == null) {
      mapLock.timedLock(timeoutSeconds * 1000, function (error) {
        if (error) {
            console.log('Could not get the partition map mutex lock within ' + timeoutSeconds + ' seconds, so gave up');
        } else {
            if (keyLock == null) {
                 keyLock = locks.createMutex();
                 partitionLocks[keyStr] = keyLock;
                 console.log("Created partition lock object for " + keyStr);
                 mapLock.unlock();
              }
        }
       });
  }
  
  if (keyLock != null) {
     keyLock.timedLock(timeoutSeconds * 1000, function (error) {
       console.log("Locked partition " + keyStr);
       callback();
       keyLock.unlock();
       console.log("Unlocked partition " + keyStr);
     });
  }
};
{'fraction_non_alphanumeric': 0.10911987256073277, 'fraction_numerical': 0.007168458781362007, 'mean_word_length': 2.3991880920162383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3372015', 'n_tokens_mistral': 692, 'n_tokens_neox': 676, 'n_words': 216}