Class PlainStoragePlugin
java.lang.Object
edu.stanford.slac.archiverappliance.plain.PlainStoragePlugin
- All Implemented Interfaces:
DataAtTime,ETLDest,ETLPostOptimizers,ETLSource,StorageMetrics,Reader,StoragePlugin,Writer
public class PlainStoragePlugin
extends Object
implements StoragePlugin, ETLSource, ETLDest, StorageMetrics, DataAtTime, ETLPostOptimizers
The plain PB storage plugin stores data in a chunk per PV per partition in sequential form.
No index is maintained, simple search algorithms are used to locate events.
This plugin has these configuration parameters.
- name
- This serves to identify this plugin; mandatory
- rootFolder
- This serves as the rootFolder that is prepended to the path generated for a PV+chunk ;
mandatory. One can use environment variables here; for example,
pb://localhost?name=STS&rootFolder=${ARCHAPPL_SHORT_TERM_FOLDER}&partitionGranularity=PARTITION_HOURwhere the value for ${ARCHAPPL_SHORT_TERM_FOLDER} is picked up from the environment/system properties. - partitionGranularity
- Defines the time partition granularity for this plugin.
For example, if the granularity
PARTITION_HOUR, then a new chunk is created for each hour of data. The partitions are clean; that is, they contain data only for that partition. It is possible to predict which chunk contains data for a particular instant in time and which chunks contain data for a particular time period. This is a mandatory field. - compress
- This is an optional field that defines the compression mode.
The support for zip compression is experimental.
If the zip compression is used, the
rootfolderis prepended with. If this is absent in theZIP_PREFIXrootfolder, the initialization code automatically adds it in. - hold & gather
holdandgatherare optional fields that work together to implement high/low watermarks for data transfer. By default, bothholdandgatherare 0 which leads to data being transferred out of this plugin as soon as the partition boundary is reached. You canholda certain number of partitions in this store (perhaps because this store is a high performing one). In this case, ETL does not start until the first event in this store is older thanholdpartitions. Once ETL begins, you can transfergatherpartitions at a time. For example,hold=5&gather=3lets you keep at least5-3=2partitions in this store. ETL kicks in once the oldest event is older than than5partitions and data is moved3partitions at a time.- pp
- An optional parameter, this contains a list of
post processing operatorsthat are computed and cached during ETL. During retrieval, if an exact match is found, then the data from the cached copy is used (greatly improving retrieval performance). Otherwise, the post processor is applied and the data is computed at runtime. To specify multiple post processors, use standard URL syntax like sopp=rms&pp=mean_3600 - consolidateOnShutdown
- This lets you control if ETL should push data to the subsequent store on appserver shutdown. This is useful if you are using a RAMDisk for the short term store.
- reducedata
- An optional parameter; use this parameter to reduce the data as you move it into this store.
You can use any of the
post processors
that can be used with the
ppargument. For example, if you define the LTS aspb://localhost?name=LTS&rootFolder=${ARCHAPPL_LONG_TERM_FOLDER}&partitionGranularity=PARTITION_YEAR&reducedata=firstSample_3600, then when moving data into this store, ETL will apply thefirstSample_3600operator on the raw data to reduce the data and store only the reduced data. The difference between this parameter and theppparameter is that in thereducedatacase, only the reduced data is stored. The raw data is thrown away. If you specify both theppand thereducedata, you may get unpredictable results because the raw data is necessary to precompute the caches. - etlIntoStoreIf
- An optional parameter; use this parameter to control if ETL should move data into
this store.
If the named flag specified by this parameter is false, this plugin will behave like the blackhole plugin
(and you will lose data).
Note that named flags are false by default; so the default behavior if you specify this flag and forget to
the set the named flag is to lose data.
If you don't set this flag at all; then this plugin behaves normally and will accept all the ETL data coming in.
For example, if you add a
etlIntoStoreIf=testFlag; then data will be moved into this store only if the value of the named flagtestFlagis true. - etlOutofStoreIf
- An optional parameter; use this parameter to control if ETL should move data out of
this store. If the named flag specified by this parameter is false, this plugin will behave like a bag of
holding and accumulate all the data it can.
Note that named flags are false by default; so the default behavior if you specify this flag and forget to
the set the named flag is to collect data till you run out of space.
If you don't set this flag at all; then this plugin behaves normally and will move data out as before.
For example, if you add a
etlOutofStoreIf=testFlag; then data will be moved ouf of this store only if the value of the named flagtestFlagis true.
- Author:
- mshankar
-
Constructor Summary
ConstructorsConstructorDescriptionPlainStoragePlugin(PlainFileHandler plainFileHandler) PlainStoragePlugin(PlainStorageType plainStorageType) -
Method Summary
Modifier and TypeMethodDescriptionintappendData(BasicContext context, String pvName, EventStream stream) booleanappendToETLAppendData(String pvName, EventStream stream, ETLContext context) This appends an EventStream to the ETL append data for a PV.booleancommitETLAppendData(String pvName, ETLContext context) This concatenates the ETL append data for a PV with the PV's destination data.booleanShould ETL move data from this source to the destination on shutdown.voidconvert(BasicContext context, String pvName, ConversionFunction conversionFunction) Sometimes, PVs change types, EGUs etc.dataAtTime(BasicContext context, String pvName, Instant atTime, Instant startAtTime, Period searchPeriod, BiDirectionalIterable.IterationDirection direction) Generic method to iterate over the data for specified PV.etlInfoListProcessor(ETLSource curETLSource) Path[]getAllPathsForPV(BasicContext context, String pvName) getAllStreams(String pvName, ETLContext context) Given a pv and a time, this method returns all the streams.getDataForPV(BasicContext context, String pvName, Instant startTime, Instant endTime) getDataForPV(BasicContext context, String pvName, Instant startTime, Instant endTime, PostProcessor postProcessor) getDesc()Get a string description of this plugin; one that can potentially be used in log messages and provide context.getETLStreams(String pvName, Instant currentTime, ETLContext context) Given a pv and a time, this method returns all the streams that are ready for ETL.getFirstKnownEvent(BasicContext context, String pvName) Get the first event for this PV.getLastKnownEvent(BasicContext context, String pvName) Gets the last known event in this destination.getName()Multiple PVs will probably use the same storage area and we identify the area using the name.getPostETLOptimizables(String pvName, ETLContext context) longgetTotalSpace(StorageMetricsContext storageMetricsContext) Gets the total space left on this device.Return a URL representation of this plugin suitable for parsing by StoragePluginURLParserlonggetUsableSpace(StorageMetricsContext storageMetricsContext) Gets the space available to this VM on this devicevoidinitialize(String configURL, ConfigService configService) Each storage plugin is registered to a URI scheme; for example, the PlainStoragePBPlugin uses pb:// as the scheme.voidmarkForDeletion(ETLInfo info, ETLContext context) Delete the ETLStream identifier by info when you can as it has already been consumed by the ETL destination.Provide the prefix for storage plugin urls.voidrenamePV(BasicContext context, String oldName, String newName) Change the name of a PV.booleanrunPostProcessors(String pvName, ArchDBRTypes dbrtype, ETLContext context) Run the post processors associated with this plugin if any for this pv.voidsetBackupFilesBeforeETL(boolean backupFilesBeforeETL) voidvoidsetGatherETLInPartitions(int gatherETLInPartitions) voidsetHoldETLForPartitions(int holdETLForPartitions) The hold and gather are used to implement a high/low watermark for ETL.voidvoidsetPartitionGranularity(PartitionGranularity partitionGranularity) voidsetRootFolder(String rootFolder) longspaceConsumedByPV(String pvName) Gets an estimate of the space consumed by this PV on this device.toString()
-
Constructor Details
-
PlainStoragePlugin
-
PlainStoragePlugin
-
-
Method Details
-
getDataForPV
public List<Callable<EventStream>> getDataForPV(BasicContext context, String pvName, Instant startTime, Instant endTime) throws IOException - Throws:
IOException
-
getAllPathsForPV
- Throws:
IOException
-
getDataForPV
public List<Callable<EventStream>> getDataForPV(BasicContext context, String pvName, Instant startTime, Instant endTime, PostProcessor postProcessor) throws IOException - Specified by:
getDataForPVin interfaceReader- Throws:
IOException
-
dataAtTime
public Event dataAtTime(BasicContext context, String pvName, Instant atTime, Instant startAtTime, Period searchPeriod, BiDirectionalIterable.IterationDirection direction) throws IOException Description copied from interface:DataAtTimeGeneric method to iterate over the data for specified PV. We provide a time to start the iteration at ( inclusive ) and a direction and a Predicate. The plugin then iterates ( forwards or backwards ) and calls the Predicate for each sample. The iteration stops when the Predicate returns false or when we run out of samples. Iteration also stops when we get an exception. So this mode of traversal is vulnerable to corruption in the data. We may relax this constraint later by providing a optional bool to ignore exceptions.- Specified by:
dataAtTimein interfaceDataAtTime- Parameters:
context-pvName- The PV nameatTime- Time looking for.startAtTime- Time to start looking from.searchPeriod- - An estimate on the amount of time we want to iterate. This is used to determine the appropriate chunks containing data at a very high level and thus to limit the search. The predicate itself is the one that controls when the iteration terminates. So, for example, you could specify a searchPeriod of 1 year but stop the iteration after 1 minute- Throws:
IOException-
-
appendData
- Specified by:
appendDatain interfaceWriter- Throws:
IOException
-
appendToETLAppendData
public boolean appendToETLAppendData(String pvName, EventStream stream, ETLContext context) throws IOException Description copied from interface:ETLDestThis appends an EventStream to the ETL append data for a PV.- Specified by:
appendToETLAppendDatain interfaceETLDest- Parameters:
pvName- The name of PV.stream- The EventStream to append to the append data for a PV.context- ETLContext- Returns:
- boolean True or False
- Throws:
IOException-
-
getDescription
Description copied from interface:StoragePluginGet a string description of this plugin; one that can potentially be used in log messages and provide context.- Specified by:
getDescriptionin interfaceETLDest- Specified by:
getDescriptionin interfaceETLSource- Specified by:
getDescriptionin interfaceStoragePlugin- Returns:
- description
-
etlInfoListProcessor
- Specified by:
etlInfoListProcessorin interfaceETLDest
-
initialize
Description copied from interface:StoragePluginEach storage plugin is registered to a URI scheme; for example, the PlainStoragePBPlugin uses pb:// as the scheme. Configuration for a storage plugin typically comes in as a URL like URI.- The config service identifies the storage plugin using the scheme ("pb" maps to PlainStoragePBPlugin)
- Creates an instance using the default constructor.
- Calls initialize with the complete URL.
- Specified by:
initializein interfaceStoragePlugin- Parameters:
configURL- The complete URLconfigService-- Throws:
IOException-- See Also:
-
getURLRepresentation
Return a URL representation of this plugin suitable for parsing by StoragePluginURLParser- Returns:
- ret A URL representation
-
getRootFolder
-
setRootFolder
- Throws:
IOException
-
getDesc
-
setDesc
-
getPartitionGranularity
- Specified by:
getPartitionGranularityin interfaceETLDest- Specified by:
getPartitionGranularityin interfaceETLSource
-
setPartitionGranularity
-
getETLStreams
public List<ETLInfo> getETLStreams(String pvName, Instant currentTime, ETLContext context) throws IOException Description copied from interface:ETLSourceGiven a pv and a time, this method returns all the streams that are ready for ETL. For example, if the partition granularity of a source is an hour, then this method returns all the streams that are in this source for the previous hours. Ideally, these streams must be closed for writing and should not change. The ETL process will consolidates these streams into the ETL destination, which is expected to be at a longer time granularity.- Specified by:
getETLStreamsin interfaceETLSource- Parameters:
pvName- The name of PV.currentTime- The time that is being used as the cutoff. If we pass in a timestamp way out into the future, we should return all the streams available.context- ETLContext- Returns:
- List ETLinfo
- Throws:
IOException-
-
getAllStreams
Description copied from interface:ETLSourceGiven a pv and a time, this method returns all the streams.- Specified by:
getAllStreamsin interfaceETLSource- Parameters:
pvName- The name of PV.context- ETLContext- Returns:
- List ETLinfo
- Throws:
IOException-
-
markForDeletion
Description copied from interface:ETLSourceDelete the ETLStream identifier by info when you can as it has already been consumed by the ETL destination. You can delete it later or immediately.- Specified by:
markForDeletionin interfaceETLSource- Parameters:
info- ETLInfocontext- ETLContext
-
getLastKnownEvent
Description copied from interface:WriterGets the last known event in this destination. Future events will be appended to this destination only if their timestamp is more recent than the timestamp of this event. If there is no last known event, then a null is returned.- Specified by:
getLastKnownEventin interfaceWriter- Parameters:
context-pvName- The PV name- Returns:
- Event The last known event of pvName
- Throws:
IOException-
-
getFirstKnownEvent
Description copied from interface:ReaderGet the first event for this PV. This call is used to optimize away calls to other readers that have older data.- Specified by:
getFirstKnownEventin interfaceReader- Parameters:
context-pvName- The PV name- Returns:
- Event The first event of pvName
- Throws:
IOException-
-
commitETLAppendData
Description copied from interface:ETLDestThis concatenates the ETL append data for a PV with the PV's destination data.- Specified by:
commitETLAppendDatain interfaceETLDest- Parameters:
pvName- The name of PV.context- ETLContext- Returns:
- boolean True or False
- Throws:
IOException-
-
runPostProcessors
public boolean runPostProcessors(String pvName, ArchDBRTypes dbrtype, ETLContext context) throws IOException Description copied from interface:ETLDestRun the post processors associated with this plugin if any for this pv. The post processing is done after the commit and outside of the ETL transaction. This process is expected to catch up on previously missed/incomplete computation of cached post processing files. I can think of at least two usecases for this - one where we decide to go back and add a post processor for a pv and one where we change the algorithm for the post processor and want to recompute all the cached files again.- Specified by:
runPostProcessorsin interfaceETLDest- Parameters:
pvName- The name of PV.dbrtype- ArchDBRTypescontext- ETLContext- Returns:
- boolean True or False
- Throws:
IOException-
-
setBackupFilesBeforeETL
public void setBackupFilesBeforeETL(boolean backupFilesBeforeETL) -
setHoldETLForPartitions
The hold and gather are used to implement a high/low watermark for ETL. ETL is skipped until the first known event in the partitions available for ETL is earlier than hold partitions. Once this is true, we then include in the ETL list all partitions whose first event is earlier than hold - gather partitions. For example, in a PARTITION_DAY, if you want to run ETL once every 7 days, but when you run you want to move 5 days worth of data to the dest, set hold to 7 and gather to 5. Hold and gather default to a scenario where we aggressively push data to the destination as soon as it is available.- Throws:
IOException
-
setGatherETLInPartitions
- Throws:
IOException
-
pluginIdentifier
Description copied from interface:StoragePluginProvide the prefix for storage plugin urls.- Specified by:
pluginIdentifierin interfaceStoragePlugin- Returns:
- String of the Storage Plugin Identifier
-
getName
Description copied from interface:StoragePluginMultiple PVs will probably use the same storage area and we identify the area using the name. This is principally used in capacity planning/load balancing to identify the storage area for the PV. We should make sure that storage's with similar lifetimes have the same name in all the appliances. The name is also used to identify the storage in the storage report. For example, the PlainStoragePlugin takes a name parameter and we should use something like STS as the identity for the short term store in all the appliances.- Specified by:
getNamein interfaceETLDest- Specified by:
getNamein interfaceETLSource- Specified by:
getNamein interfaceStorageMetrics- Specified by:
getNamein interfaceStoragePlugin- Returns:
- name
-
setName
-
getTotalSpace
Description copied from interface:StorageMetricsGets the total space left on this device.- Specified by:
getTotalSpacein interfaceStorageMetrics- Parameters:
storageMetricsContext- StorageMetricsContext- Returns:
- getTotalSpac
- Throws:
IOException-
-
getUsableSpace
Description copied from interface:StorageMetricsGets the space available to this VM on this device- Specified by:
getUsableSpacein interfaceStorageMetrics- Parameters:
storageMetricsContext- StorageMetricsContext- Returns:
- getUsableSpace
- Throws:
IOException-
-
spaceConsumedByPV
Description copied from interface:StorageMetricsGets an estimate of the space consumed by this PV on this device.- Specified by:
spaceConsumedByPVin interfaceStorageMetrics- Parameters:
pvName- The name of PV.- Returns:
- spaceConsumedByPV
- Throws:
IOException-
-
consolidateOnShutdown
public boolean consolidateOnShutdown()Description copied from interface:ETLSourceShould ETL move data from this source to the destination on shutdown. For example, if you are using a ramdisk for the STS and you have a UPS, you can minimize any data loss but turning this bit on for data stores that are on the ramdisk. On shutdown, ETL will try to move the data out of this store into the next lifetime store.- Specified by:
consolidateOnShutdownin interfaceETLSource- Returns:
- boolean True or False
-
renamePV
Description copied from interface:StoragePluginChange the name of a PV. This happens occasionally in the EPICS world when people change the names of PVs but want to retain the data. This method is used to change the name of the PV in any of the datasets for PVoldName. For example, in PB files, the name of the PV is encoded in the file names and is also stored in the header. In this case, we expect the plugin to move the data to new files names and change the PV name in the file header. To avoid getting into issues about data changing when renaming files, the PV can be assumed to be in a paused state.- Specified by:
renamePVin interfaceStoragePlugin- Parameters:
context-oldName- The old PV namenewName- The new PV name- Throws:
IOException-
-
convert
public void convert(BasicContext context, String pvName, ConversionFunction conversionFunction) throws IOException Description copied from interface:StoragePluginSometimes, PVs change types, EGUs etc. In these cases, we are left with the problem of what to do with the already archived data. We can rename the PV to a new but related name - this keeps the existing data as is. Or, we can attempt to convert to the new type, EGU etc. This method can be used to convert the existing data using the supplied conversion function. Conversions should be all or nothing; that is, first convert all the streams into temporary chunks and then do a bulk rename once all the conversions have succeeded. Note that we'll also be using the same conversion mechanism for imports and other functions that change data. So, when/if implementing the conversion function, make sure we respect the typical expectations within the archiver - monotonically increasing timestamps and so on. To avoid getting into issues about data changing when converting, the PV can be assumed to be in a paused state.- Specified by:
convertin interfaceStoragePlugin- Parameters:
context-pvName- The PV nameconversionFunction-- Throws:
IOException-
-
toString
-
getExtensionString
-
getPluginIdentifier
-
getPlainFileHandler
-
fileInfo
- Throws:
IOException
-
getPathResolver
-
getPostETLOptimizables
public Collection<ETLOptimizable> getPostETLOptimizables(String pvName, ETLContext context) throws IOException - Specified by:
getPostETLOptimizablesin interfaceETLPostOptimizers- Throws:
IOException
-