Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The FilerClient cannot set TTL #5473

Open
stillmoon opened this issue Apr 7, 2024 · 2 comments
Open

The FilerClient cannot set TTL #5473

stillmoon opened this issue Apr 7, 2024 · 2 comments

Comments

@stillmoon
Copy link

stillmoon commented Apr 7, 2024

Describe the bug

I tried to upload the file using FilerClient and set an expiration time for the file by FuseAttributes.Builder.setTtlSec.
But when the file was uploaded successfully, when I used FilerClient.lookupEntry().getAttributes().getTtlSec() to read the expiration time of the file, I found that the expiration time was still not set.

I use FilerClient in java reactive, my unit test for file upload is as follows:

@Test
  public void testUpload() {
    String content = "hello world";
    Flux<DataBuffer> dataBufferFlux = DataBufferUtils.readInputStream(
        () -> new ByteArrayInputStream(content.getBytes()),
        dataBufferFactory, 1024);
    String location = "/hello.txt";
    HashMap<String, String> metadata = new HashMap<>();
    metadata.put("mime", "text/plain");
    FilerClient filerClient = this.storageService.getFilerClient();

    long ts = System.currentTimeMillis() / 1000;
    String dir = SeaweedOutputStream.getParentDirectory(location);
    String name = SeaweedOutputStream.getFileName(location);
    FuseAttributes.Builder attributes = FuseAttributes.newBuilder()
        .setMtime(ts)
        .setCrtime(ts)
        .setFileMode(755);
    // todo  ttl 设置未生效
    attributes.setTtlSec(120);
    Builder entry = Entry.newBuilder()
        .setName(name)
        .setIsDirectory(false)
        .setAttributes(attributes.build());
    // metadata 设置
    for (Map.Entry<String, String> metadataEntry : metadata.entrySet()) {
      entry.putExtended(metadataEntry.getKey(),
          ByteString.copyFromUtf8(metadataEntry.getValue()));
    }
    SeaweedOutputStream outputStream = new SeaweedOutputStream(filerClient, location, entry, 0,
        1024, "");

    AtomicLong totalSize = new AtomicLong();
    Mono<Long> upload = DataBufferUtils.write(dataBufferFlux, outputStream)
        .doOnNext(dataBuffer -> {
          totalSize.addAndGet(dataBuffer.readableByteCount());
          DataBufferUtils.release(dataBuffer);
        })
        .doFinally(signalType -> {
          try {
            outputStream.close();
          } catch (IOException e) {
          }
        })
        .then(Mono.defer(() -> Mono.just(totalSize.get())));

    StepVerifier.create(upload)
        .expectNext(11L)
        .verifyComplete();

    Entry getEntry = filerClient.lookupEntry(dir, name);
    int ttlSec = getEntry.getAttributes().getTtlSec();
    Assert.assertEquals(120, ttlSec);

    filerClient.deleteEntry(dir, name, true, false, true);
  }

The unit test code above executed incorrectly and got a ttlSec of 0.

java.lang.AssertionError: 
Expected :120
Actual   :0
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:647)
	at org.junit.Assert.assertEquals(Assert.java:633)
	at com.hyperpaas.platform.workspace.engine.data.service.SeaweedImplITest.testPickup(SeaweedImplITest.java:283)

Look forward to your reply!

@chrislusf
Copy link
Collaborator

this is not implemented in the java client yet. You are welcome to send a PR for this.

@stillmoon
Copy link
Author

this is not implemented in the java client yet. You are welcome to send a PR for this.

oh, I'll to try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants