You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2017/04/16 10:28:45 UTC
[07/16] lucy git commit: Remove Lock_Is_Locked
Remove Lock_Is_Locked
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/38a33bad
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/38a33bad
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/38a33bad
Branch: refs/heads/master
Commit: 38a33badb310ba9fea5bf9a923277da4a82ec369
Parents: de14d4c
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 17 19:13:59 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Feb 20 16:26:22 2017 +0100
----------------------------------------------------------------------
core/Lucy/Store/Lock.c | 31 ++++++++++++++---------------
core/Lucy/Store/Lock.cfh | 22 ---------------------
go/lucy/store_test.go | 6 ------
perl/t/105-folder.t | 7 ++++---
perl/t/110-shared_lock.t | 45 ++++++++++++++++++++++---------------------
5 files changed, 41 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/38a33bad/core/Lucy/Store/Lock.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Lock.c b/core/Lucy/Store/Lock.c
index d187405..0879640 100644
--- a/core/Lucy/Store/Lock.c
+++ b/core/Lucy/Store/Lock.c
@@ -131,6 +131,12 @@ static bool
S_request(LockFileLockIVARS *ivars, String *lock_path);
static bool
+S_is_locked_exclusive(LockFileLockIVARS *ivars);
+
+static bool
+S_is_locked(LockFileLockIVARS *ivars);
+
+static bool
S_is_shared_lock_file(LockFileLockIVARS *ivars, String *entry);
static bool
@@ -194,7 +200,7 @@ LFLock_Request_Shared_IMP(LockFileLock *self) {
// race condition. We could protect the whole process with an internal
// exclusive lock.
- if (LFLock_Is_Locked_Exclusive(self)) {
+ if (S_is_locked_exclusive(ivars)) {
String *msg = Str_newf("'%o.lock' is locked", ivars->name);
Err_set_error((Err*)LockErr_new(msg));
return false;
@@ -232,8 +238,8 @@ LFLock_Request_Exclusive_IMP(LockFileLock *self) {
// exclusive lock.
if (ivars->exclusive_only
- ? LFLock_Is_Locked_Exclusive(self)
- : LFLock_Is_Locked(self)
+ ? S_is_locked_exclusive(ivars)
+ : S_is_locked(ivars)
) {
String *msg = Str_newf("'%o.lock' is locked", ivars->name);
Err_set_error((Err*)LockErr_new(msg));
@@ -352,24 +358,15 @@ LFLock_Release_IMP(LockFileLock *self) {
ivars->state = LFLOCK_STATE_UNLOCKED;
}
-bool
-LFLock_Is_Locked_Exclusive_IMP(LockFileLock *self) {
- LockFileLockIVARS *const ivars = LFLock_IVARS(self);
-
+static bool
+S_is_locked_exclusive(LockFileLockIVARS *ivars) {
return Folder_Exists(ivars->folder, ivars->lock_path)
&& !S_maybe_delete_file(ivars, ivars->lock_path, false, true);
}
-bool
-LFLock_Is_Locked_IMP(LockFileLock *self) {
- LockFileLockIVARS *const ivars = LFLock_IVARS(self);
-
- // Check for exclusive lock.
- if (Folder_Exists(ivars->folder, ivars->lock_path)
- && !S_maybe_delete_file(ivars, ivars->lock_path, false, true)
- ) {
- return true;
- }
+static bool
+S_is_locked(LockFileLockIVARS *ivars) {
+ if (S_is_locked_exclusive(ivars)) { return true; }
// Check for shared lock.
http://git-wip-us.apache.org/repos/asf/lucy/blob/38a33bad/core/Lucy/Store/Lock.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Lock.cfh b/core/Lucy/Store/Lock.cfh
index fb813e1..6688e95 100644
--- a/core/Lucy/Store/Lock.cfh
+++ b/core/Lucy/Store/Lock.cfh
@@ -96,22 +96,6 @@ abstract class Lucy::Store::Lock inherits Clownfish::Obj {
public abstract void
Release(Lock *self);
- /** Indicate whether the resource identified by this lock's name is
- * currently locked in shared or exclusive mode.
- *
- * @return true if the resource is locked, false otherwise.
- */
- public abstract bool
- Is_Locked(Lock *self);
-
- /** Indicate whether the resource identified by this lock's name is
- * currently locked in exclusive mode.
- *
- * @return true if the resource is locked, false otherwise.
- */
- public abstract bool
- Is_Locked_Exclusive(Lock *self);
-
String*
Get_Name(Lock *self);
@@ -147,12 +131,6 @@ class Lucy::Store::LockFileLock nickname LFLock
public void
Release(LockFileLock *self);
- public bool
- Is_Locked(LockFileLock *self);
-
- public bool
- Is_Locked_Exclusive(LockFileLock *self);
-
String*
Get_Lock_Path(LockFileLock *self);
http://git-wip-us.apache.org/repos/asf/lucy/blob/38a33bad/go/lucy/store_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/store_test.go b/go/lucy/store_test.go
index 89f5057..ae70069 100644
--- a/go/lucy/store_test.go
+++ b/go/lucy/store_test.go
@@ -663,9 +663,6 @@ func TestLockFileLockAll(t *testing.T) {
if err != nil {
t.Errorf("Request: %v", err)
}
- if !lock.IsLocked() {
- t.Errorf("Lock should be locked, but IsLocked returned false")
- }
if got := lock.getLockPath(); len(got) == 0 {
// Lock path only valid when locked for shared locks.
t.Errorf("getLockPath should work")
@@ -689,9 +686,6 @@ func TestLockFileLockAll(t *testing.T) {
if err != nil {
t.Errorf("Request: %v", err)
}
- if !lock.IsLocked() {
- t.Errorf("Lock should be locked, but IsLocked returned false")
- }
if got := lock.getLockPath(); len(got) == 0 {
// Lock path only valid when locked for shared locks.
t.Errorf("getLockPath should work")
http://git-wip-us.apache.org/repos/asf/lucy/blob/38a33bad/perl/t/105-folder.t
----------------------------------------------------------------------
diff --git a/perl/t/105-folder.t b/perl/t/105-folder.t
index 3d00195..ba1255e 100644
--- a/perl/t/105-folder.t
+++ b/perl/t/105-folder.t
@@ -62,16 +62,17 @@ for my $folder ( $fs_folder, $ram_folder ) {
);
$lock->obtain_exclusive();
- ok( $lock->is_locked_exclusive(), "lock is locked" );
+ my $lock_path = $lock->get_lock_path;
+ ok( $folder->exists($lock_path), "lock is locked" );
ok( !$competing_lock->obtain_exclusive(),
"shouldn't get lock on existing resource"
);
- ok( $lock->is_locked_exclusive(),
+ ok( $folder->exists($lock_path),
"lock still locked after competing attempt"
);
$lock->release;
- ok( !$lock->is_locked_exclusive(), "release works" );
+ ok( !$folder->exists($lock_path), "release works" );
$lock->obtain_exclusive();
$folder->rename( from => 'king_of_rock', to => 'king_of_lock' );
http://git-wip-us.apache.org/repos/asf/lucy/blob/38a33bad/perl/t/110-shared_lock.t
----------------------------------------------------------------------
diff --git a/perl/t/110-shared_lock.t b/perl/t/110-shared_lock.t
index 77c6862..86e7d6c 100644
--- a/perl/t/110-shared_lock.t
+++ b/perl/t/110-shared_lock.t
@@ -20,8 +20,7 @@ use Test::More tests => 14;
use Lucy::Test;
my $folder = Lucy::Store::RAMFolder->new;
-
-my $lock = Lucy::Store::LockFileLock->new(
+my @args = (
folder => $folder,
name => 'ness',
timeout => 0,
@@ -29,32 +28,34 @@ my $lock = Lucy::Store::LockFileLock->new(
exclusive_only => 0,
);
-ok( !$lock->is_locked(), "not locked yet" );
+my $ex_lock = Lucy::Store::LockFileLock->new(@args);
+
+sub is_locked {
+ if ($ex_lock->request_exclusive) {
+ $ex_lock->release;
+ return 0;
+ }
+ else {
+ return 1;
+ }
+}
+
+my $lock = Lucy::Store::LockFileLock->new(@args);
+
+ok( !is_locked(), "not locked yet" );
ok( $lock->obtain_shared(), "obtain" );
-ok( $lock->is_locked(), "is_locked" );
+ok( is_locked(), "is_locked" );
ok( $folder->exists('locks/ness-1.lock'), "lockfile exists" );
-my $another_lock = Lucy::Store::LockFileLock->new(
- folder => $folder,
- name => 'ness',
- timeout => 0,
- host => 'nessie',
- exclusive_only => 0,
-);
+my $another_lock = Lucy::Store::LockFileLock->new(@args);
ok( $another_lock->obtain_shared(), "got a second lock on the same resource" );
$lock->release;
-ok( $lock->is_locked(),
+ok( is_locked(),
"first lock released but still is_locked because of other lock" );
-my $ya_lock = Lucy::Store::LockFileLock->new(
- folder => $folder,
- name => 'ness',
- timeout => 0,
- host => 'nessie',
- exclusive_only => 0,
-);
+my $ya_lock = Lucy::Store::LockFileLock->new(@args);
ok( $ya_lock->obtain_shared(), "got yet another lock" );
ok( $lock->obtain_shared(), "got first lock again" );
@@ -75,10 +76,10 @@ $another_lock->release;
$ya_lock->release;
ok( $lock->get_lock_path, "failed to release a lock with a different pid" );
-ok( !$lock->is_locked(), "is_locked clears stale locks" );
+ok( !is_locked(), "is_locked clears stale locks" );
ok( $lock->obtain_shared(), "got lock again" );
-ok( $lock->is_locked(), "it's locked" );
+ok( is_locked(), "it's locked" );
# Rewrite lock file to spec a different host.
$content = $folder->slurp_file("locks/ness-1.lock");
@@ -89,4 +90,4 @@ $outstream->print($content);
$outstream->close;
$lock->release;
-ok( $lock->is_locked(), "don't delete lock belonging to another host" );
+ok( is_locked(), "don't delete lock belonging to another host" );