Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
72e0cb9
Tweak to moongodb index priority
PicoCreator Jul 19, 2022
c090ebd
Added read and write stream support polyfill's
PicoCreator Jul 19, 2022
61277e8
Reorganize Stack_FileWorkspaceMap code ordering
PicoCreator Jul 19, 2022
e62c4de
Adding fileRead/WriteStream stack optimization for single layer stack
PicoCreator Jul 19, 2022
dbd2b0f
Update the Core_FileWorkspaceMap error handling
PicoCreator Jul 19, 2022
28a4566
Fix build issues
PicoCreator Jul 19, 2022
a1b3f0a
Added polyfill, and unit test for Input/output stream support
PicoCreator Aug 1, 2022
5848061
Commentry tweak
PicoCreator Aug 1, 2022
009ebd6
WIP MongoDB FileWorkspaceMap
PicoCreator Aug 2, 2022
b29ee2c
Tweaks with FileWorkspaceMap
PicoCreator Aug 2, 2022
143c90b
Expeerimental MongoDB_KeyValueMap support
PicoCreator Aug 3, 2022
f051a3c
Abstract out WIP FileWorkspaceMap
PicoCreator Aug 3, 2022
16cde49
Code cleanup
PicoCreator Aug 3, 2022
370ea8e
MongoDB_KeyValueMap test
PicoCreator Aug 3, 2022
a64f356
Ensure proper reading of KeyValue expiry Date
PicoCreator Aug 3, 2022
763fa38
Add setValueRaw, enforcing the expire timestamp
PicoCreator Aug 3, 2022
3238409
Fixing expireAt_long
PicoCreator Aug 3, 2022
a3d52b3
Fixing KeyValueMap compliation issue
PicoCreator Aug 3, 2022
ebb9932
Prototype KeyLongMap implementation
PicoCreator Aug 3, 2022
d9148a4
KeyLongMap test
PicoCreator Aug 3, 2022
8fa1e61
Standardising to fileWriteInputStream (it was confused with outputStr…
PicoCreator Aug 3, 2022
17747b3
WIP FileWorkspaceMap support
PicoCreator Aug 4, 2022
5dffda3
FileWorkspaceMap test
PicoCreator Aug 4, 2022
6eb69a8
Fix invalid @Override
PicoCreator Aug 4, 2022
386875a
Polyfill basic copy / move operations
PicoCreator Aug 4, 2022
aa19c45
MongoDb file listing support
PicoCreator Aug 4, 2022
442157b
Modified timestamp support
PicoCreator Aug 4, 2022
1366b1b
Fixing compile issues
PicoCreator Aug 4, 2022
424e96f
Fixing upload pathing
PicoCreator Aug 4, 2022
717a377
Fixing rm flag status
PicoCreator Aug 4, 2022
1aa344c
Fixing file path search regex
PicoCreator Aug 4, 2022
610efd0
Tweak removeFilePathRecursively handling of empty path
PicoCreator Aug 4, 2022
8bb20a7
Core_FileWorkspaceMap enforcing system setup on write
PicoCreator Aug 5, 2022
4b5a066
Fix invalid _isUninitialized setup flag
PicoCreator Aug 5, 2022
5a3fdfc
Fixing filter typo
PicoCreator Aug 5, 2022
ec49c86
WIP fixing mongodb
PicoCreator Aug 5, 2022
5c2f9d4
Working mongodb getFileAndFolderPathSet
PicoCreator Aug 5, 2022
a9a83b9
Working query for mongodb fileworkspacemap
PicoCreator Aug 5, 2022
0e8368a
Working mongodb FileWorkspaceMap prototype (no file cleanup yet)
PicoCreator Aug 5, 2022
b4406c9
versioned cleanup for mongodb
PicoCreator Aug 8, 2022
8b18bc6
@TODO optimized getAndAdd operations
PicoCreator Aug 8, 2022
2fbda38
Added @TODO commentry
PicoCreator Aug 8, 2022
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
39 changes: 37 additions & 2 deletions src/main/java/picoded/dstack/FileWorkspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
import picoded.core.conv.StringConv;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Set;

import org.apache.commons.io.IOUtils;

/**
* Represent a file storage backend for a workspace
*
Expand Down Expand Up @@ -133,16 +138,46 @@ default void writeString(final String filepath, String content, String encoding)
//--------------------------------------------------------------------------

/**
* Get the input stream representation of a given filepath
* Get the input stream representation of a given filepath.
*
* You are expected to close, the stream on your own, to avoid memory leaks
*
* @param filePath in the workspace to extract
* @return the file contents, null if file does not exists
* @return the file contents as an input stream, null if file does not exists
*/
default InputStream readInputStream(final String filePath) {
byte[] byteArr = readByteArray(filePath);
return new ByteArrayInputStream(byteArr);
}

/**
* Reads an input stream, and writes it to a fil, creating the file if it does not exist.
* the parent directories of the file will be created if they do not exist.
*
* Note that depending on the implementaiton, this may not be optimized,
* and may only return after the OutputStream is fully processedd.
*
* @param filepath in the workspace to extract
* @param data the content to write to the file
**/
default void writeInputStream(final String filepath, final InputStream data) {
// Converts it to bytearray respectively
byte[] rawBytes = null;
try {
rawBytes = IOUtils.toByteArray(data);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
data.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
// Does the bytearray writes
writeByteArray(filepath, rawBytes);
}

//
// Folder Pathing support
//--------------------------------------------------------------------------
Expand Down
39 changes: 5 additions & 34 deletions src/main/java/picoded/dstack/KeyLongMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,39 +180,10 @@ default Long removeValue(Object key) {
**/
default Long addAndGet(Object key, Object delta) {
//
// NOTE : The default implmentation of addAndGet,
// or getAndAdd relies on repetaed tries using
// weakCompareAndSet, while functional.
// Is highly inefficent in most cases
// We simply use get and add, with the delta,
// this reduce the amount of permutation needed to support
//

// Validate and convert the key to String
if (key == null) {
throw new IllegalArgumentException("key cannot be null in addAndGet");
}
String keyAsString = key.toString();

// Attempt to update the key for 5 times before throwing exception
for (int tries = 0; tries < 5; tries++) {
// Retrieve value from key
Long value = getValue(keyAsString);

// Assume value as 0 if not exist
if (value == null) {
value = new Long(0);
}

// Calculate the updated value
Long updatedValue = GenericConvert.toLong(delta) + value;

// Update the value with weakCompareAndSet and return
if (weakCompareAndSet(keyAsString, value, updatedValue)) {
return updatedValue;
}
}

// Throw exception due to number of retries exceeded the limit
throw new RuntimeException("Number of retries exceeded limit for addAndGet");
return getAndAdd(key, delta)+GenericConvert.toLong(delta);
}

/**
Expand All @@ -233,7 +204,7 @@ default Long getAndAdd(Object key, Object delta) {

// Validate and convert the key to String
if (key == null) {
throw new IllegalArgumentException("key cannot be null in addAndGet");
throw new IllegalArgumentException("key cannot be null in");
}
String keyAsString = key.toString();

Expand All @@ -257,7 +228,7 @@ default Long getAndAdd(Object key, Object delta) {
}

// Throw exception due to number of retries exceeded the limit
throw new RuntimeException("Number of retries exceeded limit for addAndGet");
throw new RuntimeException("Number of retries exceeded limit");
}

/**
Expand Down
Loading