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

feat: initial source implementation #2

Merged
merged 20 commits into from
Jan 13, 2025
Merged

feat: initial source implementation #2

merged 20 commits into from
Jan 13, 2025

Conversation

grvsahil
Copy link
Collaborator

@grvsahil grvsahil commented Dec 13, 2024

Source implementation for SFTP connector.

Quick checks:

  • There is no other pull request for the same update/change.
  • I have written unit tests.
  • I have made sure that the PR is of reasonable size and can be easily reviewed.

@grvsahil grvsahil self-assigned this Dec 17, 2024
@parikshitg parikshitg linked an issue Dec 18, 2024 that may be closed by this pull request
2 tasks
@grvsahil grvsahil marked this pull request as ready for review December 18, 2024 21:35
Copy link

@hariso hariso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the good work!

metadata := iter.createMetadata(fileInfo, fullPath, len(chunk))
metadata["chunk_index"] = fmt.Sprintf("%d", chunkIndex)
metadata["total_chunks"] = fmt.Sprintf("%d", totalChunks)
metadata["hash"] = hash(fileInfo.modTime.Format(time.RFC3339))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: so that a user doesn't think this is the chunk content hash, it would be good to change the name to something like file_mod_time_hash, or even just the time?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking a bit about the hash. Every file with the same modification time will have the same hash, and that's quite possible. Using the file name, creation time, and/or last modification time together might be an alternative. Two files with the same path might not be the same file, because a file might have been created, then deleted, then created again with the same name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now I have used filename, mod time and filesize to create the hash.

source/source.go Outdated
Comment on lines 112 to 116
s.ch = make(chan opencdc.Record)
s.wg = &sync.WaitGroup{}

s.wg.Add(1)
err = NewIterator(ctx, s.sshClient, s.sftpClient, s.position, s.config, s.ch, s.wg)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I'm reading this code again, why do we actually need a channel that's shared between the source and the iterator? Can the iterator return a record on demand, i.e. when the source's Read() method is called, it calls iterator.Next(), and gets the next record or chunk?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now I have refactored the iterator to return records on demand.

fullPath := filepath.Join(iter.config.DirectoryPath, filename)

// Get initial file stat.
initialStat, err := iter.sftpClient.Stat(fullPath)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the source works this way: we get a list of file paths, we go through the list, and get the files.

If that's the case, then modifications to files can happen between the time when we get the list of files and when we fetch a file. A file can be moved/deleted, and in that case, I don't think we should fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this could happen, handled it now.

@parikshitg parikshitg merged commit 5ccc211 into main Jan 13, 2025
3 checks passed
@parikshitg parikshitg deleted the feat/source branch January 13, 2025 16:02
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

Successfully merging this pull request may close these issues.

Connector: SFTP [Source/Destination]
3 participants