Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
378 commits
Select commit Hold shift + click to select a range
c04b2e5
Update TableImpl.java
aftilion May 13, 2021
765f447
Update TableImpl.java
aftilion May 13, 2021
b5fd756
Update SegmentImpl.java
aftilion May 13, 2021
f8d2087
Update SegmentImpl.java
aftilion May 15, 2021
933ea86
Update SegmentImpl.java
aftilion May 15, 2021
c5165f7
Update DatabaseImpl.java
aftilion May 16, 2021
464610e
Update pom.xml
aftilion May 16, 2021
cf00777
ProtocolModel
aftilion May 16, 2021
4890748
UpdateRespBulkString
aftilion May 16, 2021
7d8804e
Create+Result in Console
aftilion May 16, 2021
6b35a6b
Console
aftilion May 16, 2021
de67279
add databasecommand enum
aftilion May 16, 2021
e74c772
command+client
aftilion May 17, 2021
59ffeb6
command+client
aftilion May 17, 2021
aa7e763
server
aftilion May 17, 2021
4ecf3b6
//test
aftilion May 17, 2021
27f0f09
Update ExecutionEnvironmentImpl.java
aftilion May 17, 2021
5999200
test
aftilion May 17, 2021
8bcefdf
test
aftilion May 17, 2021
5b8599d
test
aftilion May 17, 2021
9247764
test
aftilion May 17, 2021
0ef1202
Update SimpleKvsClient.java
aftilion May 17, 2021
5535260
ser
aftilion May 17, 2021
4597aa7
test
aftilion May 17, 2021
76d455c
s
aftilion May 17, 2021
34f5cf0
lz
aftilion May 17, 2021
f82e601
1
aftilion May 17, 2021
a6853fd
Update SegmentInitializationContextImpl.java
aftilion May 17, 2021
94f75a8
why
aftilion May 17, 2021
eed7ba2
3lab
aftilion May 17, 2021
edc1bda
3lab
aftilion May 17, 2021
b5b2950
Update SegmentInitializationContextImpl.java
aftilion May 17, 2021
7e49d01
make nice
aftilion May 17, 2021
090c326
lab3
aftilion May 17, 2021
cfa1b20
end3lab
aftilion May 18, 2021
efb53c0
start
aftilion Jun 7, 2021
148faa5
fix throw IOException
aftilion Jun 7, 2021
03b5e96
fix throw IOException
aftilion Jun 7, 2021
7f28912
fix
aftilion Jun 7, 2021
9a548e3
fix
aftilion Jun 7, 2021
0f8f8dc
fix
aftilion Jun 7, 2021
103b8fe
fix
aftilion Jun 7, 2021
96bea87
fix
aftilion Jun 7, 2021
4e05330
fix
aftilion Jun 7, 2021
f87db2e
fix
aftilion Jun 7, 2021
39683cb
RespReader(writer)
aftilion Jun 7, 2021
5b67174
whyaborted
aftilion Jun 7, 2021
a8efb40
addWriter
aftilion Jun 7, 2021
c540638
addsomereader
aftilion Jun 7, 2021
7eaf209
add readError
aftilion Jun 7, 2021
f50722a
fix readError
aftilion Jun 7, 2021
0584526
fix readError }
aftilion Jun 7, 2021
f9633ad
respError take off commits
aftilion Jun 7, 2021
1e724ef
add configLoader
aftilion Jun 7, 2021
e5f25da
ConfigLoader
aftilion Jun 7, 2021
e287ac6
CommandReader
aftilion Jun 7, 2021
3a3343f
firstSocketKvsConnection
aftilion Jun 7, 2021
5d1f14b
rewrite SocketWritrer
aftilion Jun 7, 2021
acf50f3
SocketWriter
aftilion Jun 7, 2021
155d9c8
Socket try add config
aftilion Jun 8, 2021
ee255ba
Socket try only config
aftilion Jun 8, 2021
8f13cd6
Socket try
aftilion Jun 8, 2021
d7dec6b
SocketKvs try
aftilion Jun 8, 2021
b1c0844
Socket try
aftilion Jun 8, 2021
0e20c56
SocketKvs getHost//
aftilion Jun 8, 2021
af61882
SocketKvs getHost//
aftilion Jun 8, 2021
fdd0ff4
SocketKvs test
aftilion Jun 8, 2021
84331dd
SocketKvs try write
aftilion Jun 8, 2021
dd41c74
SocketKvs
aftilion Jun 8, 2021
5490ed7
SocketKvs
aftilion Jun 8, 2021
a862db0
JavaSocket
aftilion Jun 8, 2021
30dcfb2
JavaSocket first com
aftilion Jun 8, 2021
d43d738
add start
aftilion Jun 8, 2021
96f698d
add close
aftilion Jun 8, 2021
f35bc8b
update close
aftilion Jun 8, 2021
d4ef1ea
- close
aftilion Jun 8, 2021
e854dda
Update JavaSocketServerConnector.java
aftilion Jun 8, 2021
e796542
-com
aftilion Jun 8, 2021
0eda97c
close
aftilion Jun 8, 2021
4c0dbcf
new run
aftilion Jun 8, 2021
714beb1
откат
aftilion Jun 8, 2021
bf3b429
update
aftilion Jun 8, 2021
976db07
updatenew
aftilion Jun 8, 2021
88d6621
help
aftilion Jun 8, 2021
a872b78
maybe now
aftilion Jun 8, 2021
5be96d0
minus closed
aftilion Jun 8, 2021
f68e445
new first close
aftilion Jun 8, 2021
c890c16
pp
aftilion Jun 8, 2021
71d18e6
Update JavaSocket
aftilion Jun 8, 2021
f7bcc10
try catch
aftilion Jun 8, 2021
7154566
new JavaSocket
aftilion Jun 8, 2021
48ee80d
Update JavaSocketCon
aftilion Jun 8, 2021
0d7f0cd
test start
aftilion Jun 8, 2021
acb1f47
testing
aftilion Jun 8, 2021
910eb97
testing
aftilion Jun 8, 2021
e548d64
testing
aftilion Jun 8, 2021
ba94026
testing
aftilion Jun 8, 2021
4284859
testings
aftilion Jun 8, 2021
ca892aa
testing
aftilion Jun 8, 2021
8d61ca8
testing
aftilion Jun 8, 2021
6c21366
откат
aftilion Jun 8, 2021
5af6481
RespReader
aftilion Jun 8, 2021
1bbd92d
update RespReader
aftilion Jun 8, 2021
76ac3c1
reader
aftilion Jun 8, 2021
8c8af7d
testings
aftilion Jun 8, 2021
8d7dd82
testings reader
aftilion Jun 8, 2021
5ddae8e
testing readers
aftilion Jun 8, 2021
2029923
откат
aftilion Jun 8, 2021
351d238
testing reader
aftilion Jun 8, 2021
50d390a
fix resp array
aftilion Jun 8, 2021
ade738f
откат
aftilion Jun 8, 2021
2b32997
RespReader hasArray
aftilion Jun 8, 2021
2feb2f1
откат
aftilion Jun 8, 2021
2f1080e
testing readobjects
aftilion Jun 8, 2021
883002d
readError
aftilion Jun 8, 2021
f79926d
trying
aftilion Jun 8, 2021
2d76684
try
aftilion Jun 8, 2021
044d7cc
try javasocket
aftilion Jun 8, 2021
30b2649
try socket
aftilion Jun 8, 2021
8b20869
try start
aftilion Jun 8, 2021
dcec244
try reader
aftilion Jun 8, 2021
c99ddff
try without
aftilion Jun 8, 2021
d6f709f
откат
aftilion Jun 8, 2021
6721a20
откат java socket
aftilion Jun 8, 2021
5e0163c
откат
aftilion Jun 9, 2021
487207a
socket
aftilion Jun 9, 2021
d3813d5
JavaSocket
aftilion Jun 9, 2021
7c67aa5
delete catch
aftilion Jun 9, 2021
4361f9d
add try catch Io
aftilion Jun 9, 2021
5383b82
add main
aftilion Jun 9, 2021
e18da39
откат к add io
aftilion Jun 9, 2021
c4a6394
add io
aftilion Jun 9, 2021
82634bc
откат
aftilion Jun 9, 2021
c609b77
try respreader
aftilion Jun 9, 2021
1a72bb7
tetsting reader
aftilion Jun 9, 2021
468b2e6
откат comreader
aftilion Jun 9, 2021
9a6cf96
testing
aftilion Jun 9, 2021
62b7038
откат reader
aftilion Jun 9, 2021
1d8a10e
откат
aftilion Jun 9, 2021
6f96aaf
try respreader
aftilion Jun 9, 2021
63ce2af
update + откат
aftilion Jun 9, 2021
705fedc
trying without
aftilion Jun 9, 2021
12eba85
trying
aftilion Jun 9, 2021
7e2dbe7
try
aftilion Jun 9, 2021
fd670ac
test
aftilion Jun 9, 2021
6f3e33f
откат socket
aftilion Jun 9, 2021
99f7829
test server
aftilion Jun 9, 2021
765ef0a
javasocket + откат dbserver
aftilion Jun 9, 2021
9e5592f
trying with откат
aftilion Jun 9, 2021
6c1bc97
откат к test server
aftilion Jun 9, 2021
93df907
откат
aftilion Jun 9, 2021
ce24b91
maybe?
aftilion Jun 9, 2021
712391c
new id
aftilion Jun 9, 2021
e667343
main
aftilion Jun 9, 2021
0a2afe1
откат
aftilion Jun 9, 2021
80bf674
откат
aftilion Jun 9, 2021
85a4394
run
aftilion Jun 9, 2021
0cd8c3c
trying
aftilion Jun 9, 2021
1f432b6
fix config
aftilion Jun 9, 2021
44422b1
fixing config
aftilion Jun 9, 2021
0f35901
test config
aftilion Jun 9, 2021
c20eaf8
test constructor socket
aftilion Jun 9, 2021
c308753
fix config
aftilion Jun 9, 2021
48565aa
fix Dbservice
aftilion Jun 9, 2021
3d8ff67
add output.flush()
aftilion Jun 9, 2021
6339153
check connection
aftilion Jun 9, 2021
dec0931
getAndIncrement
aftilion Jun 9, 2021
51f7b8a
откат(хз получился ли)
aftilion Jun 9, 2021
5d58073
DelKey
aftilion Jun 9, 2021
a7e2d59
откат
aftilion Jun 9, 2021
9eb7357
try fix console
aftilion Jun 9, 2021
f26b10d
mm
aftilion Jun 9, 2021
8564d99
try fix
aftilion Jun 9, 2021
5836d84
мб?
aftilion Jun 9, 2021
37f6491
try fix
aftilion Jun 9, 2021
bd47563
откат config
aftilion Jun 10, 2021
164ddb3
- gradle
aftilion Jun 10, 2021
a717d44
откат к 123 коммиту
aftilion Jun 10, 2021
8558410
откат 123
aftilion Jun 10, 2021
d976aef
откат 123 end
aftilion Jun 10, 2021
65b292c
test with this config
aftilion Jun 10, 2021
303536c
fix socket
aftilion Jun 10, 2021
c9aa1cf
new Server Initializer
aftilion Jun 10, 2021
bb3ab22
fixxx
aftilion Jun 10, 2021
128e57e
add DatabaseeExecutionException
aftilion Jun 10, 2021
b4ab9f7
DbExEx
aftilion Jun 10, 2021
2868ad4
try
aftilion Jun 10, 2021
034a86d
add success and error DatavaseCommandResult
aftilion Jun 10, 2021
ce244aa
откат
aftilion Jun 10, 2021
5164214
откат
aftilion Jun 10, 2021
b18a500
- value.isEmpty
aftilion Jun 10, 2021
1fa3e97
value not found
aftilion Jun 10, 2021
edbe814
DaleteKey
aftilion Jun 10, 2021
26858b9
откат console
aftilion Jun 10, 2021
d9f3a50
try fix DeleteKeyCommand
aftilion Jun 10, 2021
d361447
откат del
aftilion Jun 10, 2021
602933a
add some new assert for fixing
aftilion Jun 10, 2021
522890d
- value is empty in Get Key command
aftilion Jun 10, 2021
e3a4bee
откат socketKvs
aftilion Jun 10, 2021
71ce8cd
testing
aftilion Jun 10, 2021
4be101b
try fix input
aftilion Jun 10, 2021
0329401
try input
aftilion Jun 10, 2021
c1e71e0
fix
aftilion Jun 10, 2021
e375ede
откат
aftilion Jun 10, 2021
269d86e
откат RespReader
aftilion Jun 10, 2021
7a041f8
откат
aftilion Jun 10, 2021
7fea849
откат
aftilion Jun 10, 2021
f9902be
try
aftilion Jun 10, 2021
5404702
откат
aftilion Jun 10, 2021
5302658
help
aftilion Jun 10, 2021
6b889d4
try
aftilion Jun 10, 2021
58db567
откат
aftilion Jun 10, 2021
ac8e45a
testing elder reader
aftilion Jun 10, 2021
f64b11d
откат
aftilion Jun 10, 2021
a4bf431
testing
aftilion Jun 10, 2021
850e8d2
откат
aftilion Jun 10, 2021
d70cf98
testing
aftilion Jun 10, 2021
2d2476c
maybe
aftilion Jun 10, 2021
1f79abf
s
aftilion Jun 10, 2021
1000d44
откат в 4.40
aftilion Jun 10, 2021
725e640
test
aftilion Jun 10, 2021
c9ca223
deleteKvsCom
aftilion Jun 10, 2021
417575c
z
aftilion Jun 10, 2021
b89e836
Response
aftilion Jun 10, 2021
26bac0b
Update CreateDatabaseCommand.java
aftilion Jun 10, 2021
a168f26
fixing protocol
aftilion Jun 10, 2021
92ad49c
fix client
aftilion Jun 10, 2021
96fb0ec
fix and откат
aftilion Jun 10, 2021
2df181b
откат + try
aftilion Jun 10, 2021
ff77a52
fix console
aftilion Jun 10, 2021
4340284
fix console
aftilion Jun 10, 2021
f3c067e
fix console
aftilion Jun 10, 2021
65a1e79
try
aftilion Jun 10, 2021
7902e7c
try2
aftilion Jun 10, 2021
dc90372
try2
aftilion Jun 10, 2021
a2415c8
1
aftilion Jun 10, 2021
c3da827
1
aftilion Jun 10, 2021
6d3ae14
try
aftilion Jun 10, 2021
ab2aba6
try
aftilion Jun 10, 2021
2173686
try
aftilion Jun 10, 2021
0f3129c
try fix and make nice
aftilion Jun 10, 2021
f863454
try fiz dirCvsCon
aftilion Jun 10, 2021
d527063
make command nice
aftilion Jun 10, 2021
313c290
откат SimpleKvs
aftilion Jun 10, 2021
6332e6e
откат config
aftilion Jun 10, 2021
8f29ccd
Check protocol
aftilion Jun 10, 2021
7446626
check client
aftilion Jun 10, 2021
98ea744
fix
aftilion Jun 10, 2021
1663d1b
small fix
aftilion Jun 10, 2021
6708b4f
Update SimpleKvsClient.java
aftilion Jun 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/main/java/com/itmo/java/basics/DatabaseServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.itmo.java.basics.console.*;
import com.itmo.java.basics.exceptions.DatabaseException;
import com.itmo.java.basics.initialization.impl.*;
import com.itmo.java.basics.initialization.InitializationContext;
import com.itmo.java.basics.initialization.impl.DatabaseServerInitializer;
import com.itmo.java.basics.initialization.impl.InitializationContextImpl;
import com.itmo.java.protocol.model.RespArray;

import java.util.concurrent.CompletableFuture;
Expand All @@ -11,31 +13,36 @@

public class DatabaseServer {

private final ExecutorService executorService = Executors.newSingleThreadExecutor();
private final ExecutionEnvironment enviroment;
private ExecutorService executorService = Executors.newSingleThreadExecutor();
private final ExecutionEnvironment environment;

/**
* Con structor
* Конструктор
*
* @param env env для инициализации. Далее работа происходит с заполненым объектом
* @param env env для инициализации. Далее работа происходит с заполненным объектом
* @param initializer готовый чейн инициализации
* @throws DatabaseException если произошла ошибка инициализации
*/
public static DatabaseServer initialize(ExecutionEnvironment env, DatabaseServerInitializer initializer) throws DatabaseException {
initializer.perform(new InitializationContextImpl(env, null, null, null));
InitializationContext context = InitializationContextImpl.builder().executionEnvironment(env).build();
initializer.perform(context);
return new DatabaseServer(env);
}

private DatabaseServer(ExecutionEnvironment env) {
this.enviroment = env;
this.environment = env;
}

public CompletableFuture<DatabaseCommandResult> executeNextCommand(RespArray message) {
return CompletableFuture.supplyAsync(() ->
DatabaseCommands.valueOf(message.getObjects().get(DatabaseCommandArgPositions.COMMAND_NAME.getPositionIndex()).asString()).getCommand(enviroment, message.getObjects()).execute(), executorService);
return CompletableFuture.supplyAsync(() -> DatabaseCommands.valueOf(message.getObjects().get(DatabaseCommandArgPositions.
COMMAND_NAME.getPositionIndex()).asString()).getCommand(environment, message.getObjects()).execute(), executorService);
}

public CompletableFuture<DatabaseCommandResult> executeNextCommand(DatabaseCommand command) {
return CompletableFuture.supplyAsync(command::execute, executorService);
}

public ExecutionEnvironment getEnv() {
return environment;
}
}
68 changes: 0 additions & 68 deletions src/main/java/com/itmo/java/basics/MainTest.java

This file was deleted.

89 changes: 89 additions & 0 deletions src/main/java/com/itmo/java/basics/config/ConfigLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.itmo.java.basics.config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
* Класс, отвечающий за подгрузку данных из конфигурационного файла формата .properties
*/
public class ConfigLoader {
private static final String DEFAULT_PROPERTY_FILE = "server.properties";

private InputStream propertyInputStream;

/**
* По умолчанию читает из server.properties
*/
public ConfigLoader() {
propertyInputStream = getClass().getClassLoader().getResourceAsStream(DEFAULT_PROPERTY_FILE);
if (this.propertyInputStream == null) {
try {
this.propertyInputStream = new FileInputStream(DEFAULT_PROPERTY_FILE);
} catch (FileNotFoundException e) {
this.propertyInputStream = null;
}
}
}

/**
* @param name Имя конфикурационного файла, откуда читать
*/
public ConfigLoader(String name) {
this.propertyInputStream = getClass().getClassLoader().getResourceAsStream(name);
if (this.propertyInputStream == null) {
try {
this.propertyInputStream = new FileInputStream(name);
} catch (FileNotFoundException e) {
this.propertyInputStream = null;
}
}
}

/**
* Считывает конфиг из указанного в конструкторе файла.
* Если не удалось считать из заданного файла, или какого-то конкретно значения не оказалось,
* то используют дефолтные значения из {@link DatabaseConfig} и {@link ServerConfig}
* <br/>
* Читаются: "kvs.workingPath", "kvs.host", "kvs.port" (но в конфигурационном файле допустимы и другие проперти)
*/
public DatabaseServerConfig readConfig() {
Properties properties = new Properties();
try {
if (propertyInputStream == null) {
throw new IOException("Config file not found");
}
properties.load(propertyInputStream);
String workingPath = properties.getProperty("kvs.workingPath");
String host = properties.getProperty("kvs.host");
String portStr = properties.getProperty("kvs.port");
DatabaseConfig databaseConfig;
ServerConfig serverConfig;
if (workingPath == null) {
databaseConfig = new DatabaseConfig();
} else {
databaseConfig = new DatabaseConfig(workingPath);
}
if (host == null){
host = ServerConfig.DEFAULT_HOST;
}
try {
int port = Integer.parseInt(portStr);
serverConfig = new ServerConfig(host, port);
} catch (NumberFormatException e) {
serverConfig = new ServerConfig(host, ServerConfig.DEFAULT_PORT);
}
return DatabaseServerConfig.builder()
.dbConfig(databaseConfig)
.serverConfig(serverConfig)
.build();
} catch (IOException e) {
return DatabaseServerConfig.builder()
.dbConfig(new DatabaseConfig())
.serverConfig(new ServerConfig(ServerConfig.DEFAULT_HOST, ServerConfig.DEFAULT_PORT))
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.itmo.java.basics.config;

public class DatabaseConfig {

public class DatabaseConfig {
public static final String DEFAULT_WORKING_PATH = "db_files";
private final String workingPath;

public DatabaseConfig(String workingPath) {
this.workingPath = workingPath;
}

public DatabaseConfig(){
this.workingPath = DEFAULT_WORKING_PATH;
}

public String getWorkingPath() {
return workingPath;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.itmo.java.basics.config;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

@ToString
@Getter
@Builder
public class DatabaseServerConfig {
private final ServerConfig serverConfig;

private final DatabaseConfig dbConfig;
}
19 changes: 19 additions & 0 deletions src/main/java/com/itmo/java/basics/config/ServerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.itmo.java.basics.config;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* Какой хост и какой порт будет слушать наш сервер
*/
@Getter
@AllArgsConstructor
public class ServerConfig {

public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 8080;

private final String host;
private final int port;

}
Loading