未验证 提交 8e6fc511 编写于 作者: V Vlad Ilyushchenko 提交者: GitHub

chore(server): introduced version of web console and removed -f command line arg (#528)

上级 70d52faa
......@@ -24,27 +24,6 @@
package io.questdb;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URL;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.concurrent.locks.LockSupport;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import io.questdb.cairo.CairoEngine;
import io.questdb.cutlass.http.HttpServer;
import io.questdb.cutlass.line.tcp.LineTcpServer;
......@@ -59,15 +38,22 @@ import io.questdb.log.LogFactory;
import io.questdb.log.LogRecord;
import io.questdb.mp.WorkerPool;
import io.questdb.network.NetworkError;
import io.questdb.std.CharSequenceObjHashMap;
import io.questdb.std.Chars;
import io.questdb.std.Misc;
import io.questdb.std.Os;
import io.questdb.std.Vect;
import io.questdb.std.*;
import io.questdb.std.time.Dates;
import sun.misc.Signal;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.locks.LockSupport;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ServerMain {
private static final String VERSION_TXT = "version.txt";
public static void deleteOrException(File file) {
if (!file.exists()) {
return;
......@@ -107,7 +93,7 @@ public class ServerMain {
// -n = disables handling of HUP signal
final String rootDirectory = optHash.get("-d");
extractSite(rootDirectory, optHash.get("-f") != null, log);
extractSite(rootDirectory, log);
final Properties properties = new Properties();
final String configurationFileName = "/server.conf";
final File configurationFile = new File(new File(rootDirectory, PropServerConfiguration.CONFIG_DIRECTORY), configurationFileName);
......@@ -291,29 +277,56 @@ public class ServerMain {
return optHash;
}
private static void extractSite(String dir, boolean force, Log log) throws IOException {
private static long getPublicVersion(String publicDir) throws IOException {
File f = new File(publicDir, VERSION_TXT);
if (f.exists()) {
try (FileInputStream fis = new FileInputStream(f)) {
byte[] buf = new byte[128];
int len = fis.read(buf);
return Long.parseLong(new String(buf, 0, len));
}
}
return Long.MIN_VALUE;
}
private static void setPublicVersion(String publicDir, long version) throws IOException {
File f = new File(publicDir, VERSION_TXT);
try (FileOutputStream fos = new FileOutputStream(f)) {
byte[] buf = Long.toString(version).getBytes();
fos.write(buf, 0, buf.length);
}
}
private static void extractSite(String dir, Log log) throws IOException {
final String publicZip = "/io/questdb/site/public.zip";
final String publicDest = dir + "/public";
final String publicDir = dir + "/public";
final byte[] buffer = new byte[1024 * 1024];
try (final InputStream is = ServerMain.class.getResourceAsStream(publicZip)) {
if (is != null) {
try (ZipInputStream zip = new ZipInputStream(is)) {
ZipEntry ze;
while ((ze = zip.getNextEntry()) != null) {
final File dest = new File(publicDest, ze.getName());
if (!ze.isDirectory()) {
copyInputStream(force, buffer, dest, zip, log);
final long thisVersion = ServerMain.class.getResource(publicZip).openConnection().getLastModified();
final long oldVersion = getPublicVersion(publicDir);
if (thisVersion > oldVersion) {
try (final InputStream is = ServerMain.class.getResourceAsStream(publicZip)) {
if (is != null) {
try (ZipInputStream zip = new ZipInputStream(is)) {
ZipEntry ze;
while ((ze = zip.getNextEntry()) != null) {
final File dest = new File(publicDir, ze.getName());
if (!ze.isDirectory()) {
copyInputStream(true, buffer, dest, zip, log);
}
zip.closeEntry();
}
zip.closeEntry();
}
} else {
log.error().$("could not find site [resource=").$(publicZip).$(']').$();
}
} else {
log.error().$("could not find site [resource=").$(publicZip).$(']').$();
}
setPublicVersion(publicDir, thisVersion);
copyConfResource(dir, false, buffer, "conf/date.formats", log);
copyConfResource(dir, true, buffer, "conf/mime.types", log);
copyConfResource(dir, false, buffer, "conf/server.conf", log);
} else {
log.info().$("web console is up to date").$();
}
copyConfResource(dir, false, buffer, "conf/date.formats", log);
copyConfResource(dir, force, buffer, "conf/mime.types", log);
copyConfResource(dir, false, buffer, "conf/server.conf", log);
}
private static void copyConfResource(String dir, boolean force, byte[] buffer, String res, Log log) throws IOException {
......
......@@ -30,6 +30,7 @@ import io.questdb.log.LogFactory;
import io.questdb.std.*;
import io.questdb.std.microtime.Timestamps;
import io.questdb.std.str.Path;
import org.jetbrains.annotations.NotNull;
import java.io.Closeable;
import java.util.concurrent.locks.LockSupport;
......@@ -1039,16 +1040,7 @@ public class TableReader implements Closeable {
if (ff.exists(TableUtils.dFile(path.trimTo(plen), name))) {
if (mem1 != null && mem1 != NullColumn.INSTANCE) {
mem1.of(ff, path, ff.getMapPageSize(), ff.length(path));
} else {
if (lastPartition) {
mem1 = new ReadOnlyMemory(ff, path, ff.getMapPageSize(), 0);
} else {
mem1 = new OnePageMemory(ff, path, ff.length(path));
}
columns.setQuick(primaryIndex, mem1);
}
mem1 = openOrCreateMemory(path, columns, lastPartition, primaryIndex, mem1);
final long columnTop = TableUtils.readColumnTop(ff, path.trimTo(plen), name, plen, tempMem8b);
final int type = metadata.getColumnType(columnIndex);
......@@ -1057,16 +1049,7 @@ public class TableReader implements Closeable {
case ColumnType.BINARY:
case ColumnType.STRING:
TableUtils.iFile(path.trimTo(plen), name);
if (mem2 != null && mem2 != NullColumn.INSTANCE) {
mem2.of(ff, path, ff.getMapPageSize(), ff.length(path));
} else {
if (lastPartition) {
mem2 = new ReadOnlyMemory(ff, path, ff.getMapPageSize(), 0);
} else {
mem2 = new OnePageMemory(ff, path, ff.length(path));
}
columns.setQuick(secondaryIndex, mem2);
}
mem2 = openOrCreateMemory(path, columns, lastPartition, secondaryIndex, mem2);
growColumn(mem1, mem2, type, partitionRowCount - columnTop);
break;
default:
......@@ -1105,6 +1088,21 @@ public class TableReader implements Closeable {
}
}
@NotNull
private ReadOnlyColumn openOrCreateMemory(Path path, ObjList<ReadOnlyColumn> columns, boolean lastPartition, int primaryIndex, ReadOnlyColumn mem) {
if (mem != null && mem != NullColumn.INSTANCE) {
mem.of(ff, path, ff.getMapPageSize(), ff.length(path));
} else {
if (lastPartition) {
mem = new ReadOnlyMemory(ff, path, ff.getMapPageSize(), 0);
} else {
mem = new OnePageMemory(ff, path, ff.length(path));
}
columns.setQuick(primaryIndex, mem);
}
return mem;
}
private void reloadColumnChanges() {
// create transition index, which will help us reuse already open resources
long pTransitionIndex = metadata.createTransitionIndex();
......
......@@ -125,7 +125,7 @@ public class StaticContentProcessor implements HttpRequestProcessor, Closeable {
private void send(HttpConnectionContext context, LPSZ path, boolean asAttachment) throws PeerDisconnectedException, PeerIsSlowToReadException {
int n = Chars.lastIndexOf(path, '.');
if (n == -1) {
LOG.info().$("Missing extension: ").$(path).$();
logInfoWithFd(context).$("missing extension [file=").$(path).$(']').$();
sendStatusWithDefaultMessage(context, 404);
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册