Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7345f4fc
提交
7345f4fc
authored
10月 16, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Opening a connection with AUTO_SERVER=TRUE is now fast.
上级
1a5fa020
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
65 行增加
和
9 行删除
+65
-9
Database.java
h2/src/main/org/h2/engine/Database.java
+14
-8
SessionRemote.java
h2/src/main/org/h2/engine/SessionRemote.java
+1
-0
TcpServerThread.java
h2/src/main/org/h2/server/TcpServerThread.java
+9
-0
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+41
-0
TestAutoServer.java
h2/src/test/org/h2/test/server/TestAutoServer.java
+0
-1
没有找到文件。
h2/src/main/org/h2/engine/Database.java
浏览文件 @
7345f4fc
...
...
@@ -220,7 +220,13 @@ public class Database implements DataHandler {
}
}
catch
(
Exception
e
)
{
if
(
traceSystem
!=
null
)
{
traceSystem
.
getTrace
(
Trace
.
DATABASE
).
error
(
"opening "
+
databaseName
,
e
);
if
(
e
instanceof
SQLException
)
{
SQLException
e2
=
(
SQLException
)
e
;
if
(
e2
.
getErrorCode
()
!=
ErrorCode
.
DATABASE_ALREADY_OPEN_1
)
{
// only write if the database is not already in use
traceSystem
.
getTrace
(
Trace
.
DATABASE
).
error
(
"opening "
+
databaseName
,
e
);
}
}
traceSystem
.
close
();
}
closeOpenFilesAndUnlock
();
...
...
@@ -495,13 +501,7 @@ public class Database implements DataHandler {
if
(
FileUtils
.
exists
(
dataFileName
))
{
// if it is already read-only because ACCESS_MODE_DATA=r
readOnly
=
readOnly
|
FileUtils
.
isReadOnly
(
dataFileName
);
textStorage
=
isTextStorage
(
dataFileName
,
textStorage
);
lobFilesInDirectories
&=
!
ValueLob
.
existsLobFile
(
getDatabasePath
());
lobFilesInDirectories
|=
FileUtils
.
exists
(
databaseName
+
Constants
.
SUFFIX_LOBS_DIRECTORY
);
}
}
dummy
=
DataPage
.
create
(
this
,
0
);
if
(
persistent
)
{
}
if
(
readOnly
)
{
traceSystem
=
new
TraceSystem
(
null
,
false
);
}
else
{
...
...
@@ -526,6 +526,12 @@ public class Database implements DataHandler {
startServer
(
lock
.
getUniqueId
());
}
}
if
(
FileUtils
.
exists
(
dataFileName
))
{
textStorage
=
isTextStorage
(
dataFileName
,
textStorage
);
lobFilesInDirectories
&=
!
ValueLob
.
existsLobFile
(
getDatabasePath
());
lobFilesInDirectories
|=
FileUtils
.
exists
(
databaseName
+
Constants
.
SUFFIX_LOBS_DIRECTORY
);
}
dummy
=
DataPage
.
create
(
this
,
0
);
deleteOldTempFiles
();
log
=
new
LogSystem
(
this
,
databaseName
,
readOnly
,
accessModeLog
);
openFileData
();
...
...
h2/src/main/org/h2/engine/SessionRemote.java
浏览文件 @
7345f4fc
...
...
@@ -56,6 +56,7 @@ public class SessionRemote implements SessionInterface, DataHandler {
public
static
final
int
SESSION_PREPARE_READ_PARAMS
=
11
;
public
static
final
int
SESSION_SET_ID
=
12
;
public
static
final
int
SESSION_CANCEL_STATEMENT
=
13
;
public
static
final
int
SESSION_CHECK_KEY
=
14
;
public
static
final
int
STATUS_ERROR
=
0
;
public
static
final
int
STATUS_OK
=
1
;
...
...
h2/src/main/org/h2/server/TcpServerThread.java
浏览文件 @
7345f4fc
...
...
@@ -83,8 +83,17 @@ public class TcpServerThread implements Runnable {
int
command
=
transfer
.
readInt
();
stop
=
true
;
if
(
command
==
SessionRemote
.
SESSION_CANCEL_STATEMENT
)
{
// cancel a running statement
int
statementId
=
transfer
.
readInt
();
server
.
cancelStatement
(
sessionId
,
statementId
);
}
else
if
(
command
==
SessionRemote
.
SESSION_CHECK_KEY
)
{
// check if this is the correct server
db
=
server
.
checkKeyAndGetDatabaseName
(
sessionId
);
if
(!
sessionId
.
equals
(
db
))
{
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
);
}
else
{
transfer
.
writeInt
(
SessionRemote
.
STATUS_ERROR
);
}
}
}
String
baseDir
=
server
.
getBaseDir
();
...
...
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
7345f4fc
...
...
@@ -19,6 +19,8 @@ import java.util.Properties;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.engine.SessionRemote
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.message.Message
;
import
org.h2.message.Trace
;
...
...
@@ -28,6 +30,7 @@ import org.h2.util.ByteUtils;
import
org.h2.util.NetUtils
;
import
org.h2.util.RandomUtils
;
import
org.h2.util.SortedProperties
;
import
org.h2.value.Transfer
;
/**
* The file lock is used to lock a database so that only one process can write
...
...
@@ -120,6 +123,7 @@ public class FileLock {
public
synchronized
void
lock
(
String
fileName
,
boolean
allowSocket
)
throws
SQLException
{
this
.
fs
=
FileSystem
.
getInstance
(
fileName
);
this
.
fileName
=
fileName
;
checkServer
();
if
(
locked
)
{
throw
Message
.
getInternalError
(
"already locked"
);
}
...
...
@@ -204,6 +208,43 @@ public class FileLock {
throw
getException
(
e
);
}
}
private
void
checkServer
()
throws
SQLException
{
Properties
prop
=
load
();
String
server
=
prop
.
getProperty
(
"server"
);
if
(
server
==
null
)
{
return
;
}
boolean
running
=
false
;
String
id
=
prop
.
getProperty
(
"id"
);
try
{
Socket
socket
=
NetUtils
.
createSocket
(
server
,
Constants
.
DEFAULT_SERVER_PORT
,
false
);
Transfer
transfer
=
new
Transfer
(
null
);
transfer
.
setSocket
(
socket
);
transfer
.
init
();
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_6
);
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_6
);
transfer
.
writeString
(
null
);
transfer
.
writeString
(
null
);
transfer
.
writeString
(
id
);
transfer
.
writeInt
(
SessionRemote
.
SESSION_CHECK_KEY
);
transfer
.
flush
();
int
state
=
transfer
.
readInt
();
if
(
state
==
SessionRemote
.
STATUS_OK
)
{
running
=
true
;
}
transfer
.
close
();
socket
.
close
();
}
catch
(
IOException
e
)
{
return
;
}
if
(
running
)
{
String
payload
=
server
+
"/"
+
id
;
JdbcSQLException
ex
=
Message
.
getSQLException
(
ErrorCode
.
DATABASE_ALREADY_OPEN_1
,
"Server is running"
);
ex
.
setPayload
(
payload
);
throw
ex
;
}
}
private
Properties
load
()
throws
SQLException
{
try
{
...
...
h2/src/test/org/h2/test/server/TestAutoServer.java
浏览文件 @
7345f4fc
...
...
@@ -59,7 +59,6 @@ public class TestAutoServer extends TestBase {
if
(
i
<=
0
)
{
fail
();
}
Connection
conn
=
getConnection
(
url
+
";OPEN_NEW=TRUE"
);
Statement
stat
=
conn
.
createStatement
();
if
(
config
.
big
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论