Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
2d4f153e
提交
2d4f153e
authored
1月 30, 2018
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use enum for file lock method
上级
469a69ea
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
80 行增加
和
71 行删除
+80
-71
Database.java
h2/src/main/org/h2/engine/Database.java
+23
-22
Engine.java
h2/src/main/org/h2/engine/Engine.java
+3
-3
FileLister.java
h2/src/main/org/h2/store/FileLister.java
+1
-1
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+11
-38
FileLockMethod.java
h2/src/main/org/h2/store/FileLockMethod.java
+35
-0
TestFileLock.java
h2/src/test/org/h2/test/unit/TestFileLock.java
+7
-7
没有找到文件。
h2/src/main/org/h2/engine/Database.java
浏览文件 @
2d4f153e
...
...
@@ -44,6 +44,7 @@ import org.h2.schema.Sequence;
import
org.h2.schema.TriggerObject
;
import
org.h2.store.DataHandler
;
import
org.h2.store.FileLock
;
import
org.h2.store.FileLockMethod
;
import
org.h2.store.FileStore
;
import
org.h2.store.InDoubtTransaction
;
import
org.h2.store.LobStorageBackend
;
...
...
@@ -139,7 +140,7 @@ public class Database implements DataHandler {
private
boolean
starting
;
private
TraceSystem
traceSystem
;
private
Trace
trace
;
private
final
int
fileLockMethod
;
private
final
FileLockMethod
fileLockMethod
;
private
Role
publicRole
;
private
final
AtomicLong
modificationDataId
=
new
AtomicLong
();
private
final
AtomicLong
modificationMetaId
=
new
AtomicLong
();
...
...
@@ -235,14 +236,14 @@ public class Database implements DataHandler {
}
if
(
dbSettings
.
mvStore
&&
lockMethodName
==
null
)
{
if
(
autoServerMode
)
{
fileLockMethod
=
FileLock
.
LOCK_
FILE
;
fileLockMethod
=
FileLock
Method
.
FILE
;
}
else
{
fileLockMethod
=
FileLock
.
LOCK_
FS
;
fileLockMethod
=
FileLock
Method
.
FS
;
}
}
else
{
fileLockMethod
=
FileLock
.
getFileLockMethod
(
lockMethodName
);
}
if
(
dbSettings
.
mvStore
&&
fileLockMethod
==
FileLock
.
LOCK_
SERIALIZED
)
{
if
(
dbSettings
.
mvStore
&&
fileLockMethod
==
FileLock
Method
.
SERIALIZED
)
{
throw
DbException
.
getUnsupportedException
(
"MV_STORE combined with FILE_LOCK=SERIALIZED"
);
}
...
...
@@ -407,7 +408,7 @@ public class Database implements DataHandler {
*/
private
synchronized
boolean
reconnectModified
(
boolean
pending
)
{
if
(
readOnly
||
lock
==
null
||
fileLockMethod
!=
FileLock
.
LOCK_
SERIALIZED
)
{
fileLockMethod
!=
FileLock
Method
.
SERIALIZED
)
{
return
true
;
}
try
{
...
...
@@ -516,7 +517,7 @@ public class Database implements DataHandler {
}
if
(
lock
!=
null
)
{
stopServer
();
if
(
fileLockMethod
!=
FileLock
.
LOCK_
SERIALIZED
)
{
if
(
fileLockMethod
!=
FileLock
Method
.
SERIALIZED
)
{
// allow testing shutdown
lock
.
unlock
();
}
...
...
@@ -646,9 +647,9 @@ public class Database implements DataHandler {
trace
.
info
(
"opening {0} (build {1})"
,
databaseName
,
Constants
.
BUILD_ID
);
if
(
autoServerMode
)
{
if
(
readOnly
||
fileLockMethod
==
FileLock
.
LOCK_
NO
||
fileLockMethod
==
FileLock
.
LOCK_
SERIALIZED
||
fileLockMethod
==
FileLock
.
LOCK_
FS
||
fileLockMethod
==
FileLock
Method
.
NO
||
fileLockMethod
==
FileLock
Method
.
SERIALIZED
||
fileLockMethod
==
FileLock
Method
.
FS
||
!
persistent
)
{
throw
DbException
.
getUnsupportedException
(
"autoServerMode && (readOnly || "
+
...
...
@@ -665,8 +666,8 @@ public class Database implements DataHandler {
"Lock file exists: "
+
lockFileName
);
}
}
if
(!
readOnly
&&
fileLockMethod
!=
FileLock
.
LOCK_
NO
)
{
if
(
fileLockMethod
!=
FileLock
.
LOCK_
FS
)
{
if
(!
readOnly
&&
fileLockMethod
!=
FileLock
Method
.
NO
)
{
if
(
fileLockMethod
!=
FileLock
Method
.
FS
)
{
lock
=
new
FileLock
(
traceSystem
,
lockFileName
,
Constants
.
LOCK_SLEEP
);
lock
.
lock
(
fileLockMethod
);
if
(
autoServerMode
)
{
...
...
@@ -1260,7 +1261,7 @@ public class Database implements DataHandler {
return
;
}
throwLastBackgroundException
();
if
(
fileLockMethod
==
FileLock
.
LOCK_
SERIALIZED
&&
if
(
fileLockMethod
==
FileLock
Method
.
SERIALIZED
&&
!
reconnectChangePending
)
{
// another connection may have written something - don't write
try
{
...
...
@@ -1437,8 +1438,8 @@ public class Database implements DataHandler {
}
closeFiles
();
if
(
persistent
&&
lock
==
null
&&
fileLockMethod
!=
FileLock
.
LOCK_
NO
&&
fileLockMethod
!=
FileLock
.
LOCK_
FS
)
{
fileLockMethod
!=
FileLock
Method
.
NO
&&
fileLockMethod
!=
FileLock
Method
.
FS
)
{
// everything already closed (maybe in checkPowerOff)
// don't delete temp files in this case because
// the database could be open now (even from within another process)
...
...
@@ -1456,7 +1457,7 @@ public class Database implements DataHandler {
lobSession
=
null
;
}
if
(
lock
!=
null
)
{
if
(
fileLockMethod
==
FileLock
.
LOCK_
SERIALIZED
)
{
if
(
fileLockMethod
==
FileLock
Method
.
SERIALIZED
)
{
// wait before deleting the .lock file,
// otherwise other connections can not detect that
if
(
lock
.
load
().
containsKey
(
"changePending"
))
{
...
...
@@ -1985,7 +1986,7 @@ public class Database implements DataHandler {
if
(
readOnly
)
{
throw
DbException
.
get
(
ErrorCode
.
DATABASE_IS_READ_ONLY
);
}
if
(
fileLockMethod
==
FileLock
.
LOCK_
SERIALIZED
)
{
if
(
fileLockMethod
==
FileLock
Method
.
SERIALIZED
)
{
if
(!
reconnectChangePending
)
{
throw
DbException
.
get
(
ErrorCode
.
DATABASE_IS_READ_ONLY
);
}
...
...
@@ -2542,7 +2543,7 @@ public class Database implements DataHandler {
if
(
pageSize
!=
Constants
.
DEFAULT_PAGE_SIZE
)
{
pageStore
.
setPageSize
(
pageSize
);
}
if
(!
readOnly
&&
fileLockMethod
==
FileLock
.
LOCK_
FS
)
{
if
(!
readOnly
&&
fileLockMethod
==
FileLock
Method
.
FS
)
{
pageStore
.
setLockFile
(
true
);
}
pageStore
.
setLogMode
(
logMode
);
...
...
@@ -2578,7 +2579,7 @@ public class Database implements DataHandler {
* @return true if reconnecting is required
*/
public
boolean
isReconnectNeeded
()
{
if
(
fileLockMethod
!=
FileLock
.
LOCK_
SERIALIZED
)
{
if
(
fileLockMethod
!=
FileLock
Method
.
SERIALIZED
)
{
return
false
;
}
if
(
reconnectChangePending
)
{
...
...
@@ -2632,7 +2633,7 @@ public class Database implements DataHandler {
* the .lock.db file.
*/
public
void
checkpointIfRequired
()
{
if
(
fileLockMethod
!=
FileLock
.
LOCK_
SERIALIZED
||
if
(
fileLockMethod
!=
FileLock
Method
.
SERIALIZED
||
readOnly
||
!
reconnectChangePending
||
closing
)
{
return
;
}
...
...
@@ -2661,7 +2662,7 @@ public class Database implements DataHandler {
}
public
boolean
isFileLockSerialized
()
{
return
fileLockMethod
==
FileLock
.
LOCK_
SERIALIZED
;
return
fileLockMethod
==
FileLock
Method
.
SERIALIZED
;
}
private
void
flushSequences
()
{
...
...
@@ -2695,7 +2696,7 @@ public class Database implements DataHandler {
* false if another connection was faster
*/
public
boolean
beforeWriting
()
{
if
(
fileLockMethod
!=
FileLock
.
LOCK_
SERIALIZED
)
{
if
(
fileLockMethod
!=
FileLock
Method
.
SERIALIZED
)
{
return
true
;
}
while
(
checkpointRunning
)
{
...
...
@@ -2724,7 +2725,7 @@ public class Database implements DataHandler {
* This method is called after updates are finished.
*/
public
void
afterWriting
()
{
if
(
fileLockMethod
!=
FileLock
.
LOCK_
SERIALIZED
)
{
if
(
fileLockMethod
!=
FileLock
Method
.
SERIALIZED
)
{
return
;
}
synchronized
(
reconnectSync
)
{
...
...
h2/src/main/org/h2/engine/Engine.java
浏览文件 @
2d4f153e
...
...
@@ -7,7 +7,6 @@ package org.h2.engine;
import
java.util.HashMap
;
import
java.util.Objects
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.Parser
;
...
...
@@ -15,6 +14,7 @@ import org.h2.command.dml.SetTypes;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.store.FileLock
;
import
org.h2.store.FileLockMethod
;
import
org.h2.util.MathUtils
;
import
org.h2.util.ThreadDeadlockDetector
;
import
org.h2.util.Utils
;
...
...
@@ -141,8 +141,8 @@ public class Engine implements SessionFactory {
try
{
ConnectionInfo
backup
=
null
;
String
lockMethodName
=
ci
.
getProperty
(
"FILE_LOCK"
,
null
);
int
fileLockMethod
=
FileLock
.
getFileLockMethod
(
lockMethodName
);
if
(
fileLockMethod
==
FileLock
.
LOCK_
SERIALIZED
)
{
FileLockMethod
fileLockMethod
=
FileLock
.
getFileLockMethod
(
lockMethodName
);
if
(
fileLockMethod
==
FileLock
Method
.
SERIALIZED
)
{
// In serialized mode, database instance sharing is not possible
ci
.
setProperty
(
"OPEN_NEW"
,
"TRUE"
);
try
{
...
...
h2/src/main/org/h2/store/FileLister.java
浏览文件 @
2d4f153e
...
...
@@ -41,7 +41,7 @@ public class FileLister {
FileLock
lock
=
new
FileLock
(
new
TraceSystem
(
null
),
fileName
,
Constants
.
LOCK_SLEEP
);
try
{
lock
.
lock
(
FileLock
.
LOCK_
FILE
);
lock
.
lock
(
FileLock
Method
.
FILE
);
lock
.
unlock
();
}
catch
(
DbException
e
)
{
throw
DbException
.
get
(
...
...
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
2d4f153e
...
...
@@ -35,33 +35,6 @@ import org.h2.value.Transfer;
*/
public
class
FileLock
implements
Runnable
{
/**
* This locking method means no locking is used at all.
*/
public
static
final
int
LOCK_NO
=
0
;
/**
* This locking method means the cooperative file locking protocol should be
* used.
*/
public
static
final
int
LOCK_FILE
=
1
;
/**
* This locking method means a socket is created on the given machine.
*/
public
static
final
int
LOCK_SOCKET
=
2
;
/**
* This locking method means multiple writers are allowed, and they
* synchronize themselves.
*/
public
static
final
int
LOCK_SERIALIZED
=
3
;
/**
* Use the file system to lock the file; don't use a separate lock file.
*/
public
static
final
int
LOCK_FS
=
4
;
private
static
final
String
MAGIC
=
"FileLock"
;
private
static
final
String
FILE
=
"file"
;
private
static
final
String
SOCKET
=
"socket"
;
...
...
@@ -125,22 +98,22 @@ public class FileLock implements Runnable {
* @param fileLockMethod the file locking method to use
* @throws DbException if locking was not successful
*/
public
synchronized
void
lock
(
int
fileLockMethod
)
{
public
synchronized
void
lock
(
FileLockMethod
fileLockMethod
)
{
checkServer
();
if
(
locked
)
{
DbException
.
throwInternalError
(
"already locked"
);
}
switch
(
fileLockMethod
)
{
case
LOCK_
FILE:
case
FILE:
lockFile
();
break
;
case
LOCK_
SOCKET:
case
SOCKET:
lockSocket
();
break
;
case
LOCK_
SERIALIZED:
case
SERIALIZED:
lockSerialized
();
break
;
case
LOCK_
FS:
case
FS:
break
;
}
locked
=
true
;
...
...
@@ -480,17 +453,17 @@ public class FileLock implements Runnable {
* @return the method type
* @throws DbException if the method name is unknown
*/
public
static
int
getFileLockMethod
(
String
method
)
{
public
static
FileLockMethod
getFileLockMethod
(
String
method
)
{
if
(
method
==
null
||
method
.
equalsIgnoreCase
(
"FILE"
))
{
return
FileLock
.
LOCK_
FILE
;
return
FileLock
Method
.
FILE
;
}
else
if
(
method
.
equalsIgnoreCase
(
"NO"
))
{
return
FileLock
.
LOCK_
NO
;
return
FileLock
Method
.
NO
;
}
else
if
(
method
.
equalsIgnoreCase
(
"SOCKET"
))
{
return
FileLock
.
LOCK_
SOCKET
;
return
FileLock
Method
.
SOCKET
;
}
else
if
(
method
.
equalsIgnoreCase
(
"SERIALIZED"
))
{
return
FileLock
.
LOCK_
SERIALIZED
;
return
FileLock
Method
.
SERIALIZED
;
}
else
if
(
method
.
equalsIgnoreCase
(
"FS"
))
{
return
FileLock
.
LOCK_
FS
;
return
FileLock
Method
.
FS
;
}
else
{
throw
DbException
.
get
(
ErrorCode
.
UNSUPPORTED_LOCK_METHOD_1
,
method
);
...
...
h2/src/main/org/h2/store/FileLockMethod.java
0 → 100644
浏览文件 @
2d4f153e
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
store
;
public
enum
FileLockMethod
{
/**
* This locking method means no locking is used at all.
*/
NO
,
/**
* This locking method means the cooperative file locking protocol should be
* used.
*/
FILE
,
/**
* This locking method means a socket is created on the given machine.
*/
SOCKET
,
/**
* This locking method means multiple writers are allowed, and they
* synchronize themselves.
*/
SERIALIZED
,
/**
* Use the file system to lock the file; don't use a separate lock file.
*/
FS
;
}
h2/src/test/org/h2/test/unit/TestFileLock.java
浏览文件 @
2d4f153e
...
...
@@ -7,11 +7,11 @@ package org.h2.test.unit;
import
java.io.File
;
import
java.sql.Connection
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.message.TraceSystem
;
import
org.h2.store.FileLock
;
import
org.h2.store.FileLockMethod
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -77,7 +77,7 @@ public class TestFileLock extends TestBase implements Runnable {
f
.
setLastModified
(
System
.
currentTimeMillis
()
+
10000
);
FileLock
lock
=
new
FileLock
(
new
TraceSystem
(
null
),
getFile
(),
Constants
.
LOCK_SLEEP
);
lock
.
lock
(
FileLock
.
LOCK_
FILE
);
lock
.
lock
(
FileLock
Method
.
FILE
);
lock
.
unlock
();
}
...
...
@@ -86,14 +86,14 @@ public class TestFileLock extends TestBase implements Runnable {
Constants
.
LOCK_SLEEP
);
FileLock
lock2
=
new
FileLock
(
new
TraceSystem
(
null
),
getFile
(),
Constants
.
LOCK_SLEEP
);
lock1
.
lock
(
FileLock
.
LOCK_
FILE
);
lock1
.
lock
(
FileLock
Method
.
FILE
);
createClassProxy
(
FileLock
.
class
);
assertThrows
(
ErrorCode
.
DATABASE_ALREADY_OPEN_1
,
lock2
).
lock
(
FileLock
.
LOCK_
FILE
);
FileLock
Method
.
FILE
);
lock1
.
unlock
();
lock2
=
new
FileLock
(
new
TraceSystem
(
null
),
getFile
(),
Constants
.
LOCK_SLEEP
);
lock2
.
lock
(
FileLock
.
LOCK_
FILE
);
lock2
.
lock
(
FileLock
Method
.
FILE
);
lock2
.
unlock
();
}
...
...
@@ -123,8 +123,8 @@ public class TestFileLock extends TestBase implements Runnable {
while
(!
stop
)
{
lock
=
new
FileLock
(
new
TraceSystem
(
null
),
getFile
(),
100
);
try
{
lock
.
lock
(
allowSockets
?
FileLock
.
LOCK_
SOCKET
:
FileLock
.
LOCK_
FILE
);
lock
.
lock
(
allowSockets
?
FileLock
Method
.
SOCKET
:
FileLock
Method
.
FILE
);
base
.
trace
(
lock
+
" locked"
);
locks
++;
if
(
locks
>
1
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论