Commit 8abed585 authored by amir.yosef's avatar amir.yosef

disabling vector api

parent a87b5250
...@@ -2,6 +2,5 @@ ...@@ -2,6 +2,5 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/key_value-server" vcs="Git" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -16,10 +16,10 @@ public class SetCommand implements CommandHandler { ...@@ -16,10 +16,10 @@ public class SetCommand implements CommandHandler {
public void execute(List<String> commands, OutputStream os) { public void execute(List<String> commands, OutputStream os) {
Map<String, String> commandsMap = new HashMap<>(); Map<String, String> commandsMap = new HashMap<>();
//
// for (int i = 2; i < commands.size(); i += 2) { for (int i = 2; i < commands.size(); i += 2) {
// commandsMap.put(commands.get(i).toLowerCase(), commands.get(i + 1)); commandsMap.put(commands.get(i).toLowerCase(), commands.get(i + 1));
// } }
String value = commands.get(2); String value = commands.get(2);
......
...@@ -9,7 +9,6 @@ import util.CommandUtil; ...@@ -9,7 +9,6 @@ import util.CommandUtil;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class ClientCommandHandler { public class ClientCommandHandler {
...@@ -24,11 +23,12 @@ public class ClientCommandHandler { ...@@ -24,11 +23,12 @@ public class ClientCommandHandler {
public boolean execute() { public boolean execute() {
Command command = CommandUtil.getCommand(commands.getFirst().split(" ")[0]); Command command = CommandUtil.getCommand(commands.getFirst());
System.out.println(command);
System.out.println("Command " + commands);
CommandHandler commandProcessor = new CommandFactory(command).getInstance(); CommandHandler commandProcessor = new CommandFactory(command).getInstance();
List<String> commandAndArgs = Arrays.stream(commands.getFirst().split(" ")).toList();
try { try {
CommandInvoker.invoke(commandProcessor, commandAndArgs, os); CommandInvoker.invoke(commandProcessor, commands, os);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
package storage; package storage;
//
import jdk.incubator.vector.ByteVector; //import jdk.incubator.vector.ByteVector;
import jdk.incubator.vector.VectorMask; //import jdk.incubator.vector.VectorMask;
import jdk.incubator.vector.VectorOperators; //import jdk.incubator.vector.VectorOperators;
import jdk.incubator.vector.VectorSpecies; //import jdk.incubator.vector.VectorSpecies;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -13,7 +13,7 @@ public class Storage { ...@@ -13,7 +13,7 @@ public class Storage {
private final Map<String, Long> timeToExpiration = new ConcurrentHashMap<>(10000); private final Map<String, Long> timeToExpiration = new ConcurrentHashMap<>(10000);
private final Map<String, Long> currentTimeForKey = new ConcurrentHashMap<>(10000); private final Map<String, Long> currentTimeForKey = new ConcurrentHashMap<>(10000);
private static final VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_128; //private static final VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_128;
private Storage() { private Storage() {
// RdbFileReader reader = new RdbFileReader(); // RdbFileReader reader = new RdbFileReader();
...@@ -45,44 +45,44 @@ public class Storage { ...@@ -45,44 +45,44 @@ public class Storage {
public String get(String key) { public String get(String key) {
System.out.println("GET Storage: " + key); System.out.println("GET Storage: " + key);
if (isExpired(key)) { // if (isExpired(key)) {
System.out.println("Key expired: " + key); // System.out.println("Key expired: " + key);
return ""; // return "";
} // }
return storage.get(key); return storage.get(key);
} }
//
private boolean isExpired(String key) { // private boolean isExpired(String key) {
long currentTime = System.currentTimeMillis(); // long currentTime = System.currentTimeMillis();
//
if (timeToExpiration.containsKey(key)) { // if (timeToExpiration.containsKey(key)) {
long expirationTime = timeToExpiration.get(key); // long expirationTime = timeToExpiration.get(key);
//
if (currentTimeForKey.containsKey(key)) { // if (currentTimeForKey.containsKey(key)) {
long currExpiration = currentTimeForKey.get(key); // long currExpiration = currentTimeForKey.get(key);
long timeDiff = currentTime - currExpiration; // long timeDiff = currentTime - currExpiration;
return vectorizedComparison(timeDiff, expirationTime); // return vectorizedComparison(timeDiff, expirationTime);
} else { // } else {
return vectorizedComparison(currentTime, expirationTime); // return vectorizedComparison(currentTime, expirationTime);
} // }
} // }
return false; // return false;
} // }
private boolean vectorizedComparison(long timeDiff, long expirationTime) { // private boolean vectorizedComparison(long timeDiff, long expirationTime) {
// Convert timeDiff and expirationTime to byte arrays for SIMD processing // // Convert timeDiff and expirationTime to byte arrays for SIMD processing
byte[] timeDiffBytes = longToBytes(timeDiff); // byte[] timeDiffBytes = longToBytes(timeDiff);
byte[] expirationTimeBytes = longToBytes(expirationTime); // byte[] expirationTimeBytes = longToBytes(expirationTime);
//
ByteVector timeDiffVector = ByteVector.fromArray(SPECIES, timeDiffBytes, 0); // ByteVector timeDiffVector = ByteVector.fromArray(SPECIES, timeDiffBytes, 0);
ByteVector expirationTimeVector = ByteVector.fromArray(SPECIES, expirationTimeBytes, 0); // ByteVector expirationTimeVector = ByteVector.fromArray(SPECIES, expirationTimeBytes, 0);
//
//
VectorMask<Byte> mask = timeDiffVector.compare(VectorOperators.GT, expirationTimeVector); // VectorMask<Byte> mask = timeDiffVector.compare(VectorOperators.GT, expirationTimeVector);
//
return mask.anyTrue(); // return mask.anyTrue();
} // }
private byte[] longToBytes(long value) { private byte[] longToBytes(long value) {
byte[] bytes = new byte[8]; byte[] bytes = new byte[8];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment