19.7. 索引配置¶
使用GeoMesa文件系统数据存储(FSD)创建新要素类型时,必须指定多个必需选项。通过命令行工具,这些选项显示为标志。如果使用GeoTools数据存储API,则必须在调用之前将选项设置为用户数据 createSchema
。
19.7.1. 配置文件编码¶
FSD目前支持三种文件编码选项: orc
, parquet
,以及 converter
。ORC和Parket都支持读写,而 converter
是一种合成的只读格式,支持使用 GeoMesa转换器 原料药。
可以通过用户数据密钥指定文件编码 geomesa.fs.encoding
:
import org.locationtech.geomesa.fs.storage.common.interop.ConfigurationUtils;
SimpleFeatureType sft = ...
// use the utility method
ConfigurationUtils.setEncoding(sft, "parquet");
// or set directly in the user data
sft.getUserData().put("geomesa.fs.encoding", "parquet");
import org.locationtech.geomesa.fs.storage.common.RichSimpleFeatureType
val sft: SimpleFeatureType = ???
// use the implicit method from RichSimpleFeatureType
sft.setEncoding("parquet")
// or set directly in the user data
sft.getUserData.put("geomesa.fs.encoding", "parquet");
19.7.2. 配置分区方案¶
分区方案定义数据文件在文件系统上的文件夹中的布局方式。方案由众所周知的名称和配置值的可选映射来定义。看见 分区方案 了解更多详细信息。
分区方案可以通过用户数据密钥指定 geomesa.fs.scheme
:
import org.locationtech.geomesa.fs.storage.common.interop.ConfigurationUtils;
import java.util.Collections;
SimpleFeatureType sft = ...
// use the utility method
ConfigurationUtils.setScheme(sft, "daily", Collections.singletonMap("dtg-attribute", "dtg"));
// or set directly in the user data as JSON
sft.getUserData().put("geomesa.fs.scheme",
"{ \"name\": \"daily\", \"options\": { \"dtg-attribute\": \"dtg\" } }");
import org.locationtech.geomesa.fs.storage.common.RichSimpleFeatureType
val sft: SimpleFeatureType = ???
// use the implicit method from RichSimpleFeatureType
sft.setScheme("daily", Map("dtg-attribute" -> "dtg"))
// or set directly in the user data
sft.getUserData.put("geomesa.fs.scheme",
"""{ "name": "daily", "options": { "dtg-attribute": "dtg" } }""")
19.7.3. 配置叶存储¶
叶存储控制文件和文件夹的最终布局。使用叶存储(默认情况下启用)时,分区路径的最后一个组件用作数据文件名的前缀,而不是用作单独的文件夹。这可以减少文件系统(如S3)的目录开销。
例如,一个分区方案 yyyy/MM/dd
会产生一个分区路径,如 2016/01/01
。使用叶存储,该分区的数据文件将为 2016/01/01_<datafile>.parquet
。如果禁用叶存储,则数据文件将为 2016/01/01/<datafile>.parquet
,创建额外的目录级别。
可以通过用户数据密钥指定叶存储 geomesa.fs.leaf-storage
:
import org.locationtech.geomesa.fs.storage.common.interop.ConfigurationUtils;
SimpleFeatureType sft = ...
// use the utility method
ConfigurationUtils.setLeafStorage(sft, false);
// or set directly in the user data as a string
sft.getUserData().put("geomesa.fs.leaf-storage", "false");
import org.locationtech.geomesa.fs.storage.common.RichSimpleFeatureType
val sft: SimpleFeatureType = ???
// use the implicit method from RichSimpleFeatureType
sft.setLeafStorage(false)
// or set directly in the user data as a string
sft.getUserData.put("geomesa.fs.leaf-storage", "false")
19.7.4. 配置目标文件大小¶
默认情况下,随着写入更多数据和压缩文件,数据文件可以增长到无限大小。如果文件变得太大,这可能会导致性能下降。为此,可以通过用户数据密钥配置目标文件大小 geomesa.fs.file-size
:
import org.locationtech.geomesa.fs.storage.common.interop.ConfigurationUtils;
SimpleFeatureType sft = ...
// use the utility method
ConfigurationUtils.setTargetFileSize(sft, false);
// or set directly in the user data as a string
sft.getUserData().put("geomesa.fs.file-size", "1GB");
import org.locationtech.geomesa.fs.storage.common.RichSimpleFeatureType
val sft: SimpleFeatureType = ???
// use the implicit method from RichSimpleFeatureType
sft.setTargetFileSize("1GB")
// or set directly in the user data as a string
sft.getUserData.put("geomesa.fs.file-size", "1GB")
请注意,还可以在某些操作中指定目标文件大小,这将覆盖在功能类型中配置的任何默认设置。看见 compact 和 ingest 了解更多细节。看见 geomesa.fs.size.threshold 用于控制文件大小误差容限。
19.7.5. 配置元数据持久性¶
FSD将元数据保存在分区和数据文件上,以避免重复询问文件系统。默认情况下,元数据信息作为更改日志存储在文件系统中,这不需要任何其他基础架构。对于更高级的用例,FSD还支持使用JDBC在关系数据库中持久化元数据。有关详细信息,请参阅 文件系统元数据 。
元数据持久性可通过用户数据密钥指定 geomesa.fs.metadata
:
import org.locationtech.geomesa.fs.storage.common.interop.ConfigurationUtils;
import java.util.Collections;
SimpleFeatureType sft = ...
// use the utility method
Map<String, String> options = Collections.singletonMap("jdbc.url", "jdbc:postgresql://localhost/geomesa");
ConfigurationUtils.setMetadata(sft, "jdbc", options);
// or set directly in the user data as JSON
sft.getUserData().put("geomesa.fs.metadata",
"{ \"name\": \"jdbc\", \"options\": { \"jdbc.url\": \"jdbc:postgresql://localhost/geomesa\" } }");
import org.locationtech.geomesa.fs.storage.common.RichSimpleFeatureType
val sft: SimpleFeatureType = ???
// use the implicit method from RichSimpleFeatureType
sft.setMetadata("jdbc", Map("jdbc.url" -> "jdbc:postgresql://localhost/geomesa"))
// or set directly in the user data as JSON
sft.getUserData.put("geomesa.fs.metadata",
"""{ "name": "jdbc", "options": { "jdbc.url": "jdbc:postgresql://localhost/geomesa" } }""")
备注
元数据配置支持使用环境变量和Java系统属性替换属性。属性替换是使用 ${}
语法,例如: ${HOME}
或 ${user.home}
。
19.7.6. 配置自定义观察器回调¶
FSD提供了一种在文件写入期间添加自定义处理的机制。用户可以实现观察器工厂,每个创建的新文件都将调用该工厂。观察者工厂必须延伸这一特征 FileSystemObserverFactory
:
package org.locationtech.geomesa.fs.storage.common.observer
trait FileSystemObserverFactory extends Closeable {
/**
* Called once after instantiating the factory
*
* @param conf hadoop configuration
* @param root root path
* @param sft simple feature type
*/
def init(conf: Configuration, root: Path, sft: SimpleFeatureType): Unit
/**
* Create an observer for the given path
*
* @param path file path being written
* @return
*/
def apply(path: Path): FileSystemObserver
}
备注
观察器工厂必须具有默认的无参数构造函数,才能被框架实例化。
可以通过用户数据密钥指定观察者 geomesa.fs.observers
:
import org.locationtech.geomesa.fs.storage.common.interop.ConfigurationUtils;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
SimpleFeatureType sft = ...
List<String> factories =
Arrays.asList("com.example.MyCustomObserverFactory", "com.example.MySecondObserverFactory");
// use the static utility method
ConfigurationUtils.setObservers(sft, factories);
// or set directly in the user data as a comma-delimited string
sft.getUserData().put("geomesa.fs.observers", String.join(",", factories));
import org.locationtech.geomesa.fs.storage.common.RichSimpleFeatureType
val sft: SimpleFeatureType = ???
val factories = Seq("com.example.MyCustomObserverFactory", "com.example.MySecondObserverFactory")
// use the implicit method from RichSimpleFeatureType
sft.setObservers(factories)
// or set directly in the user data as a comma-delimited string
sft.getUserData.put("geomesa.fs.observers", factories.mkString(","))