Coder Social home page Coder Social logo

Comments (8)

bakins avatar bakins commented on August 17, 2024

I thought about this, but TBH, when we started this, I was fairly new to Go. Let me play with it, but seems reasonable. ZFS is somewhat interesting in how volumes/filesystems/etc are treated WRT the same commands.

from go-zfs.

mdlayher avatar mdlayher commented on August 17, 2024

Yeah, certainly! I'm still fairly new to ZFS, and from a systems administrator standpoint, I appreciate how much work it does behind the scenes to blur the lines between different dataset types.

Conversely, from a programmer standpoint, I like the fact that one would never have to wonder if it's possible to send/receive/rollback a clone, since it's clear that those methods are only available and usable with a snapshot.

That is my two-cents on the matter!

from go-zfs.

bakins avatar bakins commented on August 17, 2024

Should dataset be an interface? I just wonder for times when you get a list back and just need to iterate, etc.

from go-zfs.

mdlayher avatar mdlayher commented on August 17, 2024

Good question. I suppose it could be, but that would also mean manually implementing the Name(), Used(), Avail() methods on all types, instead of relying on method promotion from the struct (since interfaces can't have struct members, Go doesn't have inheritance, etc.).

If we are trying to distinguish between dataset types, I'm not sure how helpful an interface would be in this case. I would probably still opt toward an unexported type dataset struct for embedding purposes, but perhaps some experimentation will reveal which method is easier.

from go-zfs.

mdlayher avatar mdlayher commented on August 17, 2024

As far as iterating goes, the following method could perhaps be: https://github.com/mistifyio/go-zfs/blob/master/zfs.go#L38-L41

// Snapshots returns a slice of all snapshots
func Snapshots(filter string) ([]*Snapshot, error) {
    datasets, err := listByType("snapshot", filter)
    if err != nil {
        return nil, err
    }

    snapshots := make([]*Snapshot, len(datasets))
    for i := range datasets {
        snapshots[i] = &Snapshot{
            dataset: datasets[i],
        }
    }

    return snapshots, nil
}

It's not perfect, but it would do the job.

from go-zfs.

mdlayher avatar mdlayher commented on August 17, 2024

Also, I didn't realize that this library exposed the ability to retrieve any kind of dataset. Perhaps the dataset type should be Dataset instead, so that Snapshot, Volume, and Clone still embed Dataset, but the type is still useful on its own, with its own basic methods.

from go-zfs.

mdlayher avatar mdlayher commented on August 17, 2024

Sorry for all the comments, thoughts keep coming to me. :) I'd be happy to mock up a PR in the next couple of days if you'd like.

from go-zfs.

mdlayher avatar mdlayher commented on August 17, 2024

I did a bit of quick and dirty hacking on my end, but I'm honestly not sure the result is much better. The Clone, Filesystem, and Volume types have almost no merit on their own (and no unique methods). The only type that may be worthwhile would be Snapshot, but if one is judicious in using the existing API appropriately, perhaps it's not worth the trouble.

For the time being, I'm going to close this issue. Here are the files I modified, just for reference:

https://gist.github.com/mdlayher/9cb32b96a9b6259bdf30

from go-zfs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.